mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-16 14:15:49 +01:00
Respect <C-t> for a few more key bindings. Add :background.
This commit is contained in:
@@ -207,26 +207,39 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
|
||||
{ argCount: "0" });
|
||||
},
|
||||
mappings: function initMappings(dactyl, modules, window) {
|
||||
// opening websites
|
||||
mappings.add([modes.NORMAL],
|
||||
["o"], "Open one or more URLs",
|
||||
function () { CommandExMode().open("open "); });
|
||||
let openModes = array.toObject([
|
||||
[dactyl.CURRENT_TAB, ""],
|
||||
[dactyl.NEW_TAB, "tab"],
|
||||
[dactyl.NEW_BACKGROUND_TAB, "background tab"],
|
||||
[dactyl.NEW_WINDOW, "win"]
|
||||
]);
|
||||
|
||||
function open(mode, args) {
|
||||
if (dactyl.forceTarget in openModes)
|
||||
mode = openModes[dactyl.forceTarget];
|
||||
|
||||
CommandExMode().open(mode + "open " + (args || ""))
|
||||
}
|
||||
|
||||
function decode(uri) util.losslessDecodeURI(uri)
|
||||
.replace(/%20(?!(?:%20)*$)/g, " ")
|
||||
.replace(RegExp(options["urlseparator"], "g"), encodeURIComponent);
|
||||
|
||||
mappings.add([modes.NORMAL],
|
||||
["o"], "Open one or more URLs",
|
||||
function () { open(""); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["O"],
|
||||
"Open one or more URLs, based on current location",
|
||||
function () { CommandExMode().open("open " + decode(buffer.uri.spec)); });
|
||||
function () { open("", decode(buffer.uri.spec)); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["s"],
|
||||
"Open a search prompt",
|
||||
function () { CommandExMode().open("open " + options["defsearch"] + " "); });
|
||||
function () { open("", options["defsearch"] + " "); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["S"],
|
||||
"Open a search prompt for a new tab",
|
||||
function () { CommandExMode().open("tabopen " + options["defsearch"] + " "); });
|
||||
function () { open("tab", options["defsearch"] + " "); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["t"],
|
||||
"Open one or more URLs in a new tab",
|
||||
@@ -234,15 +247,15 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
|
||||
|
||||
mappings.add([modes.NORMAL], ["T"],
|
||||
"Open one or more URLs in a new tab, based on current location",
|
||||
function () { CommandExMode().open("tabopen " + decode(buffer.uri.spec)); });
|
||||
function () { open("tab", decode(buffer.uri.spec)); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["w"],
|
||||
"Open one or more URLs in a new window",
|
||||
function () { CommandExMode().open("winopen "); });
|
||||
function () { open("win"); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["W"],
|
||||
"Open one or more URLs in a new window, based on current location",
|
||||
function () { CommandExMode().open("winopen " + decode(buffer.uri.spec)); });
|
||||
function () { open("win", decode(buffer.uri.spec)); });
|
||||
|
||||
mappings.add([modes.NORMAL], ["<open-home-directory>", "~"],
|
||||
"Open home directory",
|
||||
|
||||
@@ -592,11 +592,12 @@ var Buffer = Module("buffer", {
|
||||
}
|
||||
|
||||
let ctrlKey = false, shiftKey = false;
|
||||
switch (where) {
|
||||
switch (dactyl.forceTarget || where) {
|
||||
case dactyl.NEW_TAB:
|
||||
case dactyl.NEW_BACKGROUND_TAB:
|
||||
ctrlKey = true;
|
||||
shiftKey = (where != dactyl.NEW_BACKGROUND_TAB);
|
||||
shiftKey = dactyl.forceBackground != null ? dactyl.forceBackground
|
||||
: where != dactyl.NEW_BACKGROUND_TAB;
|
||||
break;
|
||||
case dactyl.NEW_WINDOW:
|
||||
shiftKey = true;
|
||||
|
||||
@@ -1350,6 +1350,8 @@ var CommandLine = Module("commandline", {
|
||||
arg = dactyl.userEval(arg);
|
||||
if (isObject(arg))
|
||||
arg = util.objectToString(arg, useColor);
|
||||
else if (callable(arg))
|
||||
arg = String(arg);
|
||||
else if (!isString(arg) && useColor)
|
||||
arg = template.highlight(arg);
|
||||
return arg;
|
||||
|
||||
@@ -172,8 +172,17 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
NEW_BACKGROUND_TAB: "background-tab",
|
||||
NEW_WINDOW: "window",
|
||||
|
||||
forceBackground: null,
|
||||
forceTarget: null,
|
||||
|
||||
get forceOpen() ({ background: this.forceBackground,
|
||||
target: this.forceTarget }),
|
||||
set forceOpen(val) {
|
||||
for (let [k, v] in Iterator({ background: "forceBackground", target: "forceTarget" }))
|
||||
if (k in val)
|
||||
this[v] = val[k];
|
||||
},
|
||||
|
||||
version: deprecated("config.version", { get: function version() config.version }),
|
||||
|
||||
/**
|
||||
@@ -1038,11 +1047,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
let args = null;
|
||||
|
||||
if (obj instanceof Command) {
|
||||
link = function (cmd) <ex>{cmd}</ex>;
|
||||
link = function (cmd) <ex>:{cmd}</ex>;
|
||||
args = obj.parseArgs("", CompletionContext(str || ""));
|
||||
tag = function (cmd) <>:{cmd}</>;
|
||||
spec = function (cmd) <>{
|
||||
obj.count ? <oa>count</oa> : <></>
|
||||
}{
|
||||
}:{
|
||||
cmd
|
||||
}{
|
||||
obj.bang ? <oa>!</oa> : <></>
|
||||
@@ -1228,26 +1238,28 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
}
|
||||
},
|
||||
|
||||
onClick: function onClick(event) {
|
||||
if (event.originalTarget instanceof Element) {
|
||||
let command = event.originalTarget.getAttributeNS(NS, "command");
|
||||
if (command && event.button == 0) {
|
||||
event.preventDefault();
|
||||
events: {
|
||||
click: function onClick(event) {
|
||||
if (event.originalTarget instanceof Element) {
|
||||
let command = event.originalTarget.getAttributeNS(NS, "command");
|
||||
if (command && event.button == 0) {
|
||||
event.preventDefault();
|
||||
|
||||
if (dactyl.commands[command])
|
||||
dactyl.withSavedValues(["forceTarget"], function () {
|
||||
if (event.ctrlKey || event.shiftKey || event.button == 1)
|
||||
dactyl.forceTarget = dactyl.NEW_TAB;
|
||||
dactyl.commands[command](event);
|
||||
});
|
||||
if (dactyl.commands[command])
|
||||
dactyl.withSavedValues(["forceTarget"], function () {
|
||||
if (event.ctrlKey || event.shiftKey || event.button == 1)
|
||||
dactyl.forceTarget = dactyl.NEW_TAB;
|
||||
dactyl.commands[command](event);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
onExecute: function onExecute(event) {
|
||||
let cmd = event.originalTarget.getAttribute("dactyl-execute");
|
||||
commands.execute(cmd, null, false, null,
|
||||
{ file: /*L*/"[Command Line]", line: 1 });
|
||||
"dactyl.execute": function onExecute(event) {
|
||||
let cmd = event.originalTarget.getAttribute("dactyl-execute");
|
||||
commands.execute(cmd, null, false, null,
|
||||
{ file: /*L*/"[Command Line]", line: 1 });
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1299,8 +1311,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
flags |= params[opt] && Ci.nsIWebNavigation["LOAD_FLAGS_" + flag];
|
||||
|
||||
let where = params.where || dactyl.CURRENT_TAB;
|
||||
let background = ("background" in params) ? params.background
|
||||
: params.where == dactyl.NEW_BACKGROUND_TAB;
|
||||
let background = dactyl.forceBackground != null ? dactyl.forceBackground :
|
||||
("background" in params) ? params.background
|
||||
: params.where == dactyl.NEW_BACKGROUND_TAB;
|
||||
|
||||
if (params.from && dactyl.has("tabs")) {
|
||||
if (!params.where && options.get("newtab").has(params.from))
|
||||
@@ -1547,10 +1560,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
wrapCallback: function (callback, self) {
|
||||
self = self || this;
|
||||
let save = ["forceTarget"];
|
||||
let save = ["forceOpen"];
|
||||
let saved = save.map(function (p) dactyl[p]);
|
||||
return function wrappedCallback() {
|
||||
let args = arguments;
|
||||
@@ -1576,8 +1588,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
toolbarHidden: function hidden(elem) (elem.getAttribute("autohide") || elem.getAttribute("collapsed")) == "true"
|
||||
}, {
|
||||
events: function () {
|
||||
events.listen(window, "click", dactyl.closure.onClick, true);
|
||||
events.listen(window, "dactyl.execute", dactyl.closure.onExecute, true);
|
||||
events.listen(window, dactyl, "events", true);
|
||||
},
|
||||
// Only general options are added here, which are valid for all Dactyl extensions
|
||||
options: function () {
|
||||
|
||||
@@ -352,10 +352,8 @@ var EventHive = Class("EventHive", Contexts.Hive, {
|
||||
listen: function (target, event, callback, capture, allowUntrusted) {
|
||||
if (!isObject(event))
|
||||
var [self, events] = [null, array.toObject([[event, callback]])];
|
||||
else {
|
||||
else
|
||||
[self, events] = [event, event[callback || "events"]];
|
||||
[, , capture, allowUntrusted] = arguments;
|
||||
}
|
||||
|
||||
if (Set.has(events, "input") && !Set.has(events, "dactyl-input"))
|
||||
events["dactyl-input"] = events.input;
|
||||
@@ -494,7 +492,7 @@ var Events = Module("events", {
|
||||
}
|
||||
|
||||
this._activeMenubar = false;
|
||||
this.listen(window, this, "events");
|
||||
this.listen(window, this, "events", true);
|
||||
},
|
||||
|
||||
signals: {
|
||||
|
||||
@@ -17,6 +17,8 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
this.forceOpen = opts.forceOpen || dactyl.forceOpen;
|
||||
|
||||
// Hack.
|
||||
if (!opts.window && modes.main == modes.OUTPUT_MULTILINE)
|
||||
opts.window = commandline.widgets.multilineOutput.contentWindow;
|
||||
@@ -505,9 +507,12 @@ var HintSession = Class("HintSession", CommandMode, {
|
||||
modes.push(modes.IGNORE, modes.HINTS);
|
||||
}
|
||||
|
||||
dactyl.trapErrors("action", this.hintMode,
|
||||
elem, elem.href || elem.src || "",
|
||||
this.extendedhintCount, top);
|
||||
dactyl.withSavedValues(["forceOpen"], function () {
|
||||
dactyl.forceOpen = this.forceOpen;
|
||||
dactyl.trapErrors("action", this.hintMode,
|
||||
elem, elem.href || elem.src || "",
|
||||
this.extendedhintCount, top);
|
||||
}, this);
|
||||
|
||||
this.timeout(function () {
|
||||
if (modes.main == modes.IGNORE && !this.continue)
|
||||
@@ -1030,6 +1035,11 @@ var Hints = Module("hints", {
|
||||
|
||||
open: function open(mode, opts) {
|
||||
this._extendedhintCount = opts.count;
|
||||
|
||||
opts = opts || {};
|
||||
if (!Set.has(opts, "forceOpen"))
|
||||
opts.forceOpen = dactyl.forceOpen;
|
||||
|
||||
commandline.input(["Normal", mode], "", {
|
||||
autocomplete: false,
|
||||
completer: function (context) {
|
||||
|
||||
@@ -663,6 +663,20 @@ var Tabs = Module("tabs", {
|
||||
subCommand: 0
|
||||
});
|
||||
|
||||
commands.add(["background", "bg"],
|
||||
"Execute a command opening any new tabs in the background",
|
||||
function (args) {
|
||||
dactyl.withSavedValues(["forceBackground"], function () {
|
||||
this.forceBackground = true;
|
||||
dactyl.execute(args[0], null, true);
|
||||
});
|
||||
}, {
|
||||
argCount: "1",
|
||||
completer: function (context) completion.ex(context),
|
||||
literal: 0,
|
||||
subCommand: 0
|
||||
});
|
||||
|
||||
commands.add(["tabd[o]", "bufd[o]"],
|
||||
"Execute a command in each tab",
|
||||
function (args) {
|
||||
|
||||
Reference in New Issue
Block a user