mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 10:57:58 +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;
|
lastPattern = autoCmd.pattern;
|
||||||
dactyl.echomsg("autocommand " + autoCmd.command, 9);
|
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.length > 2) { // add new command, possibly removing all others with the same event/pattern
|
||||||
if (args.bang)
|
if (args.bang)
|
||||||
autocommands.remove(event, regexp);
|
autocommands.remove(event, regexp);
|
||||||
if (args["-javascript"]) {
|
cmd = Command.bindMacro(args, "-ex", function (params) params);
|
||||||
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];
|
|
||||||
autocommands.add(events, regexp, cmd);
|
autocommands.add(events, regexp, cmd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -160,15 +160,19 @@ const Buffer = Module("buffer", {
|
|||||||
.replace(RegExp("(\\." + ext + ")?$"), "." + ext), title]);
|
.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 = {
|
let args = {
|
||||||
url: doc.location.href,
|
url: { toString: function () uri.spec, valueOf: function () uri },
|
||||||
title: doc.title
|
title: doc.title
|
||||||
};
|
};
|
||||||
|
|
||||||
if (dactyl.has("tabs")) {
|
if (dactyl.has("tabs")) {
|
||||||
args.tab = tabs.getContentIndex(doc) + 1;
|
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);
|
autocommands.trigger(name, args);
|
||||||
@@ -243,7 +247,7 @@ const Buffer = Module("buffer", {
|
|||||||
webProgress.DOMWindow.document.pageIsFullyLoaded = 0;
|
webProgress.DOMWindow.document.pageIsFullyLoaded = 0;
|
||||||
statusline.updateProgress(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
|
// don't reset mode if a frame of the frameset gets reloaded which
|
||||||
// is not the focused frame
|
// is not the focused frame
|
||||||
@@ -295,7 +299,7 @@ const Buffer = Module("buffer", {
|
|||||||
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
||||||
|
|
||||||
util.timeout(function () {
|
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
|
// if this is not delayed we get the position of the old buffer
|
||||||
|
|||||||
@@ -314,12 +314,13 @@ const Command = Class("Command", {
|
|||||||
replacementText: null
|
replacementText: null
|
||||||
}, {
|
}, {
|
||||||
bindMacro: function (args, default_, params) {
|
bindMacro: function (args, default_, params) {
|
||||||
|
let process = String;
|
||||||
let makeParams = function makeParams()
|
let makeParams = function makeParams()
|
||||||
let (args = arguments)
|
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))
|
if (callable(params))
|
||||||
makeParams = params;
|
makeParams = function makeParams(args) array(Iterator(params.apply(this, arguments))).map(function ([k, v]) [k, process(v)]).toObject();
|
||||||
else
|
else if (params)
|
||||||
params = array(params);
|
params = array(params);
|
||||||
|
|
||||||
let rhs = args.literalArg;
|
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 + "} })")
|
action = dactyl.userEval("(function action() { with (action.makeParams.apply(this, arguments)) {" + args.literalArg + "} })")
|
||||||
else
|
else
|
||||||
action = dactyl.userFunc.apply(dactyl, params.concat(args.literalArg).array);
|
action = dactyl.userFunc.apply(dactyl, params.concat(args.literalArg).array);
|
||||||
|
process = function (param) isObject(param) && param.valueOf ? param.valueOf() : param;
|
||||||
action.makeParams = makeParams;
|
action.makeParams = makeParams;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user