mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 12:07:59 +01:00
Pass proper objects to -js autocommands rather than stringified imitations.
This commit is contained in:
@@ -119,7 +119,7 @@ const AutoCommands = Module("autocommands", {
|
||||
lastPattern = autoCmd.pattern;
|
||||
dactyl.echomsg("autocommand " + autoCmd.command, 9);
|
||||
|
||||
autoCmd.command(args);
|
||||
dactyl.trapErrors(autoCmd.command, autoCmd, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,16 +155,7 @@ const AutoCommands = Module("autocommands", {
|
||||
if (args.length > 2) { // add new command, possibly removing all others with the same event/pattern
|
||||
if (args.bang)
|
||||
autocommands.remove(event, regexp);
|
||||
if (args["-javascript"]) {
|
||||
cmd = dactyl.userFunc("args", "with(args) {" + cmd + "}");
|
||||
cmd.toString = function toString() "-javascript " + cmd.source;
|
||||
}
|
||||
else {
|
||||
cmd = function cmd(args) commands.execute(cmd.source, args, false, null, cmd.sourcing);
|
||||
cmd.sourcing = io.sourcing && update({}, io.sourcing);
|
||||
cmd.toString = function toString() cmd.source;
|
||||
}
|
||||
cmd.source = args[2];
|
||||
cmd = Command.bindMacro(args, "-ex", function (params) params);
|
||||
autocommands.add(events, regexp, cmd);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -160,15 +160,19 @@ const Buffer = Module("buffer", {
|
||||
.replace(RegExp("(\\." + ext + ")?$"), "." + ext), title]);
|
||||
},
|
||||
|
||||
_triggerLoadAutocmd: function _triggerLoadAutocmd(name, doc) {
|
||||
_triggerLoadAutocmd: function _triggerLoadAutocmd(name, doc, uri) {
|
||||
uri = uri || util.newURI(doc.location.href);
|
||||
let args = {
|
||||
url: doc.location.href,
|
||||
url: { toString: function () uri.spec, valueOf: function () uri },
|
||||
title: doc.title
|
||||
};
|
||||
|
||||
if (dactyl.has("tabs")) {
|
||||
args.tab = tabs.getContentIndex(doc) + 1;
|
||||
args.doc = "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentDocument";
|
||||
args.doc = {
|
||||
valueOf: function () doc,
|
||||
toString: function () "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentDocument"
|
||||
};
|
||||
}
|
||||
|
||||
autocommands.trigger(name, args);
|
||||
@@ -243,7 +247,7 @@ const Buffer = Module("buffer", {
|
||||
webProgress.DOMWindow.document.pageIsFullyLoaded = 0;
|
||||
statusline.updateProgress(0);
|
||||
|
||||
autocommands.trigger("PageLoadPre", { url: buffer.URL });
|
||||
buffer._triggerLoadAutocmd("PageLoadPre", webProgress.DOMWindow.document);
|
||||
|
||||
// don't reset mode if a frame of the frameset gets reloaded which
|
||||
// is not the focused frame
|
||||
@@ -295,7 +299,7 @@ const Buffer = Module("buffer", {
|
||||
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
||||
|
||||
util.timeout(function () {
|
||||
autocommands.trigger("LocationChange", { url: buffer.URL });
|
||||
buffer._triggerLoadAutocmd("LocationChange", webProgress.DOMWindow ? webProgress.DOMWindow.document : content.document, uri);
|
||||
});
|
||||
|
||||
// if this is not delayed we get the position of the old buffer
|
||||
|
||||
@@ -314,12 +314,13 @@ const Command = Class("Command", {
|
||||
replacementText: null
|
||||
}, {
|
||||
bindMacro: function (args, default_, params) {
|
||||
let process = String;
|
||||
let makeParams = function makeParams()
|
||||
let (args = arguments)
|
||||
params.map(function (name, i) [name, args[i]]).toObject();
|
||||
params.map(function (name, i) [name, process(args[i])]).toObject();
|
||||
if (callable(params))
|
||||
makeParams = params;
|
||||
else
|
||||
makeParams = function makeParams(args) array(Iterator(params.apply(this, arguments))).map(function ([k, v]) [k, process(v)]).toObject();
|
||||
else if (params)
|
||||
params = array(params);
|
||||
|
||||
let rhs = args.literalArg;
|
||||
@@ -345,6 +346,7 @@ const Command = Class("Command", {
|
||||
action = dactyl.userEval("(function action() { with (action.makeParams.apply(this, arguments)) {" + args.literalArg + "} })")
|
||||
else
|
||||
action = dactyl.userFunc.apply(dactyl, params.concat(args.literalArg).array);
|
||||
process = function (param) isObject(param) && param.valueOf ? param.valueOf() : param;
|
||||
action.makeParams = makeParams;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user