mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-11 11:55:46 +01:00
Use real key bindings in MOW mode, and also restore the strange key passing behavior of yore. Closes issue #217.
This commit is contained in:
@@ -481,8 +481,8 @@ var Buffer = Module("buffer", {
|
|||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getCurrentWord: function () {
|
getCurrentWord: function (win) {
|
||||||
let win = buffer.focusedFrame || content;
|
win = win || buffer.focusedFrame || content;
|
||||||
let selection = win.getSelection();
|
let selection = win.getSelection();
|
||||||
if (selection.rangeCount == 0)
|
if (selection.rangeCount == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -720,6 +720,7 @@ var CommandLine = Module("commandline", {
|
|||||||
|
|
||||||
commandline.updateOutputHeight(true);
|
commandline.updateOutputHeight(true);
|
||||||
|
|
||||||
|
elem.scrollTop = 0;
|
||||||
if (options["more"] && Buffer.isScrollable(elem, 1)) {
|
if (options["more"] && Buffer.isScrollable(elem, 1)) {
|
||||||
// start the last executed command's output at the top of the screen
|
// start the last executed command's output at the top of the screen
|
||||||
let elements = doc.getElementsByClassName("ex-command-output");
|
let elements = doc.getElementsByClassName("ex-command-output");
|
||||||
@@ -1030,11 +1031,6 @@ var CommandLine = Module("commandline", {
|
|||||||
let win = this.widgets.multilineOutput.contentWindow;
|
let win = this.widgets.multilineOutput.contentWindow;
|
||||||
let elem = win.document.documentElement;
|
let elem = win.document.documentElement;
|
||||||
|
|
||||||
let showMoreHelpPrompt = false;
|
|
||||||
let showMorePrompt = false;
|
|
||||||
let closeWindow = false;
|
|
||||||
let passEvent = false;
|
|
||||||
|
|
||||||
let key = events.toString(event);
|
let key = events.toString(event);
|
||||||
|
|
||||||
// TODO: Wouldn't multiple handlers be cleaner? --djk
|
// TODO: Wouldn't multiple handlers be cleaner? --djk
|
||||||
@@ -1080,127 +1076,13 @@ var CommandLine = Module("commandline", {
|
|||||||
|
|
||||||
function atEnd(dir) !Buffer.isScrollable(elem, dir || 1);
|
function atEnd(dir) !Buffer.isScrollable(elem, dir || 1);
|
||||||
|
|
||||||
switch (key) {
|
if (!options["more"] || atEnd(1)) {
|
||||||
case "<Esc>":
|
passEvent = true;
|
||||||
closeWindow = true;
|
|
||||||
break; // handled globally in events.js:onEscape()
|
|
||||||
|
|
||||||
case ":":
|
|
||||||
commandline.open(":", "", modes.EX);
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// down a line
|
|
||||||
case "j":
|
|
||||||
case "<Down>":
|
|
||||||
if (options["more"])
|
|
||||||
Buffer.scrollVertical(elem, "lines", 1);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "<C-j>":
|
|
||||||
case "<C-m>":
|
|
||||||
case "<Return>":
|
|
||||||
if (options["more"] && !atEnd(1))
|
|
||||||
Buffer.scrollVertical(elem, "lines", 1);
|
|
||||||
else
|
|
||||||
closeWindow = true; // don't propagate the event for accept keys
|
|
||||||
break;
|
|
||||||
|
|
||||||
// up a line
|
|
||||||
case "k":
|
|
||||||
case "<Up>":
|
|
||||||
case "<BS>":
|
|
||||||
if (options["more"])
|
|
||||||
Buffer.scrollVertical(elem, "lines", -1);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// half page down
|
|
||||||
case "d":
|
|
||||||
if (options["more"])
|
|
||||||
Buffer.scrollVertical(elem, "pages", .5);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// TODO: <LeftMouse> on the prompt line should scroll one page
|
|
||||||
// page down
|
|
||||||
case "f":
|
|
||||||
case "<Space>":
|
|
||||||
case "<PageDown>":
|
|
||||||
if (options["more"] && !atEnd(1))
|
|
||||||
Buffer.scrollVertical(elem, "pages", 1);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// half page up
|
|
||||||
case "u":
|
|
||||||
// if (more and scrollable)
|
|
||||||
if (options["more"])
|
|
||||||
Buffer.scrollVertical(elem, "pages", -.5);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// page up
|
|
||||||
case "b":
|
|
||||||
case "<PageUp>":
|
|
||||||
if (options["more"])
|
|
||||||
Buffer.scrollVertical(elem, "pages", -1);
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// top of page
|
|
||||||
case "g":
|
|
||||||
if (options["more"])
|
|
||||||
elem.scrollTop = 0;
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// bottom of page
|
|
||||||
case "G":
|
|
||||||
if (options["more"])
|
|
||||||
elem.scrollTop = elem.scrollHeight;
|
|
||||||
else
|
|
||||||
passEvent = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// copy text to clipboard
|
|
||||||
case "<C-y>":
|
|
||||||
dactyl.clipboardWrite(window.getSelection());
|
|
||||||
break;
|
|
||||||
|
|
||||||
// close the window
|
|
||||||
case "q":
|
|
||||||
closeWindow = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ";":
|
|
||||||
hints.open(";", { window: win });
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// unmapped key
|
|
||||||
default:
|
|
||||||
if (!options["more"] || atEnd(1))
|
|
||||||
passEvent = true;
|
|
||||||
else
|
|
||||||
showMoreHelpPrompt = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (passEvent || closeWindow) {
|
|
||||||
modes.pop();
|
modes.pop();
|
||||||
|
events.feedkeys(key);
|
||||||
if (passEvent)
|
|
||||||
events.onKeyPress(event);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
commandline.updateMorePrompt(showMorePrompt, showMoreHelpPrompt);
|
commandline.updateMorePrompt(false, true);
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getSpaceNeeded: function getSpaceNeeded() {
|
getSpaceNeeded: function getSpaceNeeded() {
|
||||||
@@ -1782,6 +1664,85 @@ var CommandLine = Module("commandline", {
|
|||||||
mappings.add(myModes,
|
mappings.add(myModes,
|
||||||
["<C-n>", "<PageDown>"], "Recall the next command line from the history list",
|
["<C-n>", "<PageDown>"], "Recall the next command line from the history list",
|
||||||
function () { events.feedkeys("<S-Down>"); });
|
function () { events.feedkeys("<S-Down>"); });
|
||||||
|
|
||||||
|
// add the ":" mapping in all but insert mode mappings
|
||||||
|
mappings.add(modes.matchModes({ extended: false, input: false }),
|
||||||
|
[":"], "Enter command-line mode",
|
||||||
|
function () { commandline.open(":", "", modes.EX); });
|
||||||
|
|
||||||
|
function body() commandline.widgets.multilineOutput.contentDocument.documentElement;
|
||||||
|
function win() commandline.widgets.multilineOutput.contentWindow;
|
||||||
|
function atEnd(dir) !Buffer.isScrollable(body(), dir || 1);
|
||||||
|
|
||||||
|
mappings.add([modes.OUTPUT_MULTILINE],
|
||||||
|
["<Esc>", "<C-[>"], "Exit multi-line output mode",
|
||||||
|
function () {});
|
||||||
|
|
||||||
|
const PASS = true;
|
||||||
|
const DROP = false;
|
||||||
|
|
||||||
|
function bind(keys, description, action, test, default_) {
|
||||||
|
mappings.add([modes.OUTPUT_MULTILINE],
|
||||||
|
keys, description,
|
||||||
|
function (command) {
|
||||||
|
if (!options["more"])
|
||||||
|
var res = PASS;
|
||||||
|
else if (test && !test(command))
|
||||||
|
res = default_;
|
||||||
|
else
|
||||||
|
res = action.call(command);
|
||||||
|
util.dump(String.quote(command), res, !!test, test && test(command));
|
||||||
|
|
||||||
|
if (res === PASS || res === DROP)
|
||||||
|
modes.pop();
|
||||||
|
else
|
||||||
|
commandline.updateMorePrompt();
|
||||||
|
if (res === PASS)
|
||||||
|
events.feedkeys(command);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bind(["j", "<C-e>", "<Down>"], "Scroll down one line",
|
||||||
|
function () { Buffer.scrollVertical(body(), "lines", 1); },
|
||||||
|
function () !atEnd(1), PASS);
|
||||||
|
|
||||||
|
bind(["k", "<C-y>", "<Up>"], "Scroll up one line",
|
||||||
|
function () { Buffer.scrollVertical(body(), "lines", -1); });
|
||||||
|
|
||||||
|
bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line",
|
||||||
|
function () { Buffer.scrollVertical(body(), "lines", 1); },
|
||||||
|
function () !atEnd(1), DROP);
|
||||||
|
|
||||||
|
// half page down
|
||||||
|
bind(["<C-d>"], "Scroll down half a page",
|
||||||
|
function () { Buffer.scrollVertical(body(), "pages", .5); },
|
||||||
|
function () atEnd(1), PASS);
|
||||||
|
|
||||||
|
bind(["<C-f>", "<Space>", "<PageDown>"], "Scroll down one page",
|
||||||
|
function () { Buffer.scrollVertical(body(), "pages", 1); },
|
||||||
|
function () !atEnd(1), PASS);
|
||||||
|
|
||||||
|
bind(["<C-u>"], "Scroll up half a page",
|
||||||
|
function () { Buffer.scrollVertical(body(), "pages", -.5); });
|
||||||
|
|
||||||
|
bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
|
||||||
|
function () { Buffer.scrollVertical(body(), "pages", -1); });
|
||||||
|
|
||||||
|
bind(["gg"], "Scroll to the beginning of output",
|
||||||
|
function () { Buffer.scrollToPercent(body(), null, 0); });
|
||||||
|
|
||||||
|
bind(["G"], "Scroll to the end of output",
|
||||||
|
function () { body().scrollTop = body().scrollHeight; },
|
||||||
|
function () !atEnd(1), PASS);
|
||||||
|
|
||||||
|
// copy text to clipboard
|
||||||
|
bind(["<C-y>"], "Yank selection to clipboard",
|
||||||
|
function () { dactyl.clipboardWrite(buffer.getCurrentWord(win())); });
|
||||||
|
|
||||||
|
// close the window
|
||||||
|
bind(["q"], "Close the output window",
|
||||||
|
function () {},
|
||||||
|
function () false, DROP);
|
||||||
},
|
},
|
||||||
options: function () {
|
options: function () {
|
||||||
options.add(["history", "hi"],
|
options.add(["history", "hi"],
|
||||||
|
|||||||
@@ -1222,11 +1222,6 @@ var Events = Module("events", {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
mappings: function () {
|
mappings: function () {
|
||||||
// add the ":" mapping in all but insert mode mappings
|
|
||||||
mappings.add(modes.matchModes({ extended: false, input: false }),
|
|
||||||
[":"], "Enter command-line mode",
|
|
||||||
function () { commandline.open(":", "", modes.EX); });
|
|
||||||
|
|
||||||
mappings.add(modes.all,
|
mappings.add(modes.all,
|
||||||
["<C-z>"], "Temporarily ignore all " + config.appName + " key bindings",
|
["<C-z>"], "Temporarily ignore all " + config.appName + " key bindings",
|
||||||
function () { modes.push(modes.PASS_THROUGH); });
|
function () { modes.push(modes.PASS_THROUGH); });
|
||||||
@@ -1242,7 +1237,7 @@ var Events = Module("events", {
|
|||||||
|
|
||||||
mappings.add(modes.all,
|
mappings.add(modes.all,
|
||||||
["<Nop>"], "Do nothing",
|
["<Nop>"], "Do nothing",
|
||||||
function () { return; });
|
function () {});
|
||||||
|
|
||||||
// macros
|
// macros
|
||||||
mappings.add([modes.NORMAL, modes.TEXT_AREA, modes.PLAYER].filter(util.identity),
|
mappings.add([modes.NORMAL, modes.TEXT_AREA, modes.PLAYER].filter(util.identity),
|
||||||
|
|||||||
@@ -833,6 +833,11 @@ var Hints = Module("hints", {
|
|||||||
*/
|
*/
|
||||||
show: function show(minor, opts) {
|
show: function show(minor, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
// Hack.
|
||||||
|
if (!opts.window && modes.main == modes.OUTPUT_MULTILINE)
|
||||||
|
opts.window = commandline.widgets.multilineOutput.contentWindow;
|
||||||
|
|
||||||
this._hintMode = this._hintModes[minor];
|
this._hintMode = this._hintModes[minor];
|
||||||
dactyl.assert(this._hintMode);
|
dactyl.assert(this._hintMode);
|
||||||
|
|
||||||
@@ -1034,7 +1039,7 @@ var Hints = Module("hints", {
|
|||||||
Mode: Struct("name", "prompt", "action", "tags", "filter")
|
Mode: Struct("name", "prompt", "action", "tags", "filter")
|
||||||
}, {
|
}, {
|
||||||
mappings: function () {
|
mappings: function () {
|
||||||
var myModes = config.browserModes;
|
var myModes = config.browserModes.concat(modes.OUTPUT_MULTILINE);
|
||||||
mappings.add(myModes, ["f"],
|
mappings.add(myModes, ["f"],
|
||||||
"Start QuickHint mode",
|
"Start QuickHint mode",
|
||||||
function () { hints.show("o"); });
|
function () { hints.show("o"); });
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2008-2020 by Kris Maglione <maglione.k at Gmail>
|
// Copyright (c) 2008-2010 by Kris Maglione <maglione.k at Gmail>
|
||||||
//
|
//
|
||||||
// This work is licensed for reuse under an MIT license. Details are
|
// This work is licensed for reuse under an MIT license. Details are
|
||||||
// given in the LICENSE.txt file included with this file.
|
// given in the LICENSE.txt file included with this file.
|
||||||
|
|||||||
@@ -997,8 +997,12 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
for (let [elem, xml, attr] in iterator) {
|
for (let [elem, xml, attr] in iterator) {
|
||||||
if (elem = doc.getElementById(elem)) {
|
if (elem = doc.getElementById(elem)) {
|
||||||
let node = util.xmlToDom(xml, doc, obj.objects);
|
let node = util.xmlToDom(xml, doc, obj.objects);
|
||||||
for (let n in array.iterValues(node.childNodes))
|
if (!(node instanceof Ci.nsIDOMDocumentFragment))
|
||||||
doc.dactylOverlayElements.push(n);
|
doc.dactylOverlayElements.push(node);
|
||||||
|
else
|
||||||
|
for (let n in array.iterValues(node.childNodes))
|
||||||
|
doc.dactylOverlayElements.push(n);
|
||||||
|
|
||||||
fn(elem, node);
|
fn(elem, node);
|
||||||
for each (let attr in attr || []) // FIXME: Cleanup...
|
for each (let attr in attr || []) // FIXME: Cleanup...
|
||||||
if (attr.name() != "highlight")
|
if (attr.name() != "highlight")
|
||||||
|
|||||||
Reference in New Issue
Block a user