1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 02:47:58 +01:00

Add some MOW bindings to REPL mode. Add counts to MOW bindings.

This commit is contained in:
Kris Maglione
2011-02-17 05:50:24 -05:00
parent cdd8c918ed
commit 5bfbc6418b
2 changed files with 42 additions and 18 deletions

View File

@@ -306,13 +306,13 @@ var MOW = Module("mow", {
let bind = function bind(keys, description, action, test, default_) { let bind = function bind(keys, description, action, test, default_) {
mappings.add([modes.OUTPUT_MULTILINE], mappings.add([modes.OUTPUT_MULTILINE],
keys, description, keys, description,
function (command) { function (args) {
if (!options["more"]) if (!options["more"])
var res = PASS; var res = PASS;
else if (test && !test(command)) else if (test && !test(args))
res = default_; res = default_;
else else
res = action.call(command); res = action.call(this, args);
if (res === PASS || res === DROP) if (res === PASS || res === DROP)
modes.pop(); modes.pop();
@@ -321,48 +321,50 @@ var MOW = Module("mow", {
if (res === BEEP) if (res === BEEP)
dactyl.beep(); dactyl.beep();
else if (res === PASS) else if (res === PASS)
events.feedkeys(command); events.feedkeys(args.command);
}, {
count: action.length > 0
}); });
}; };
bind(["j", "<C-e>", "<Down>"], "Scroll down one line", bind(["j", "<C-e>", "<Down>"], "Scroll down one line",
function () { mow.scrollVertical("lines", 1); }, function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
function () mow.isScrollable(1), BEEP); function () mow.isScrollable(1), BEEP);
bind(["k", "<C-y>", "<Up>"], "Scroll up one line", bind(["k", "<C-y>", "<Up>"], "Scroll up one line",
function () { mow.scrollVertical("lines", -1); }, function ({ count }) { mow.scrollVertical("lines", -1 * (count || 1)); },
function () mow.isScrollable(-1), BEEP); function () mow.isScrollable(-1), BEEP);
bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line", bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line",
function () { mow.scrollVertical("lines", 1); }, function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
function () mow.isScrollable(1), DROP); function () mow.isScrollable(1), DROP);
// half page down // half page down
bind(["<C-d>"], "Scroll down half a page", bind(["<C-d>"], "Scroll down half a page",
function () { mow.scrollVertical("pages", .5); }, function ({ count }) { mow.scrollVertical("pages", .5 * (count || 1)); },
function () mow.isScrollable(1), BEEP); function () mow.isScrollable(1), BEEP);
bind(["<C-f>", "<PageDown>"], "Scroll down one page", bind(["<C-f>", "<PageDown>"], "Scroll down one page",
function () { mow.scrollVertical("pages", 1); }, function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
function () mow.isScrollable(1), BEEP); function () mow.isScrollable(1), BEEP);
bind(["<Space>"], "Scroll down one page", bind(["<Space>"], "Scroll down one page",
function () { mow.scrollVertical("pages", 1); }, function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
function () mow.isScrollable(1), DROP); function () mow.isScrollable(1), DROP);
bind(["<C-u>"], "Scroll up half a page", bind(["<C-u>"], "Scroll up half a page",
function () { mow.scrollVertical("pages", -.5); }, function ({ count }) { mow.scrollVertical("pages", -.5 * (count || 1)); },
function () mow.isScrollable(-1), BEEP); function () mow.isScrollable(-1), BEEP);
bind(["<C-b>", "<PageUp>"], "Scroll up half a page", bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
function () { mow.scrollVertical("pages", -1); }, function ({ count }) { mow.scrollVertical("pages", -1 * (count || 1)); },
function () mow.isScrollable(-1), BEEP); function () mow.isScrollable(-1), BEEP);
bind(["gg"], "Scroll to the beginning of output", bind(["gg"], "Scroll to the beginning of output",
function () { mow.scrollToPercent(null, 0); }); function () { mow.scrollToPercent(null, 0); });
bind(["G"], "Scroll to the end of output", bind(["G"], "Scroll to the end of output",
function () { mow.body.scrollTop = mow.body.scrollHeight; }); function ({ count }) { mow.scrollToPercent(null, count || 100); });
// copy text to clipboard // copy text to clipboard
bind(["<C-y>"], "Yank selection to clipboard", bind(["<C-y>"], "Yank selection to clipboard",

View File

@@ -693,7 +693,7 @@ var JavaScript = Module("javascript", {
}); });
}, },
commandline: function initCommandLine(dactyl, modules, window) { commandline: function initCommandLine(dactyl, modules, window) {
const { modes } = modules; const { Buffer, modes } = modules;
var REPL = Class("REPL", { var REPL = Class("REPL", {
init: function init(context) { init: function init(context) {
@@ -741,7 +741,9 @@ var JavaScript = Module("javascript", {
this.document, this); this.document, this);
return this.rootNode; return this.rootNode;
}) }),
__noSuchMethod__: function (meth, args) Buffer[meth].apply(Buffer, [this.rootNode].concat(args)),
}); });
modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, { modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, {
@@ -816,9 +818,29 @@ var JavaScript = Module("javascript", {
mappings: function initMappings(dactyl, modules, window) { mappings: function initMappings(dactyl, modules, window) {
const { mappings, modes } = modules; const { mappings, modes } = modules;
mappings.add([modes.REPL], ["<Return>"], function bind() mappings.add.apply(mappings,
"Accept the current input", [[modes.REPL]].concat(Array.slice(arguments)))
function ({ self }) { self.accept(); });
bind(["<Return>"], "Accept the current input",
function ({ self }) { self.accept(); });
bind(["<C-e>"], "Scroll down one line",
function ({ self }) { self.repl.scrollVertical("lines", 1); });
bind(["<C-y>"], "Scroll up one line",
function ({ self }) { self.repl.scrollVertical("lines", -1); });
bind(["<C-d>"], "Scroll down half a page",
function ({ self }) { self.repl.scrollVertical("pages", .5); });
bind(["<C-f>", "<PageDown>"], "Scroll down one page",
function ({ self }) { self.repl.scrollVertical("pages", 1); });
bind(["<C-u>"], "Scroll up half a page",
function ({ self }) { self.repl.scrollVertical("pages", -.5); });
bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
function ({ self }) { self.repl.scrollVertical("pages", -1); });
}, },
options: function (dactyl, modules, window) { options: function (dactyl, modules, window) {
modules.options.add(["jsdebugger", "jsd"], modules.options.add(["jsdebugger", "jsd"],