diff --git a/common/content/mow.js b/common/content/mow.js index 7d6d05b5..cb11a719 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -306,13 +306,13 @@ var MOW = Module("mow", { let bind = function bind(keys, description, action, test, default_) { mappings.add([modes.OUTPUT_MULTILINE], keys, description, - function (command) { + function (args) { if (!options["more"]) var res = PASS; - else if (test && !test(command)) + else if (test && !test(args)) res = default_; else - res = action.call(command); + res = action.call(this, args); if (res === PASS || res === DROP) modes.pop(); @@ -321,48 +321,50 @@ var MOW = Module("mow", { if (res === BEEP) dactyl.beep(); else if (res === PASS) - events.feedkeys(command); + events.feedkeys(args.command); + }, { + count: action.length > 0 }); }; bind(["j", "", ""], "Scroll down one line", - function () { mow.scrollVertical("lines", 1); }, + function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); }, function () mow.isScrollable(1), BEEP); bind(["k", "", ""], "Scroll up one line", - function () { mow.scrollVertical("lines", -1); }, + function ({ count }) { mow.scrollVertical("lines", -1 * (count || 1)); }, function () mow.isScrollable(-1), BEEP); bind(["", "", ""], "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); // half page down bind([""], "Scroll down half a page", - function () { mow.scrollVertical("pages", .5); }, + function ({ count }) { mow.scrollVertical("pages", .5 * (count || 1)); }, function () mow.isScrollable(1), BEEP); bind(["", ""], "Scroll down one page", - function () { mow.scrollVertical("pages", 1); }, + function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); }, function () mow.isScrollable(1), BEEP); bind([""], "Scroll down one page", - function () { mow.scrollVertical("pages", 1); }, + function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); }, function () mow.isScrollable(1), DROP); bind([""], "Scroll up half a page", - function () { mow.scrollVertical("pages", -.5); }, + function ({ count }) { mow.scrollVertical("pages", -.5 * (count || 1)); }, function () mow.isScrollable(-1), BEEP); bind(["", ""], "Scroll up half a page", - function () { mow.scrollVertical("pages", -1); }, + function ({ count }) { mow.scrollVertical("pages", -1 * (count || 1)); }, function () mow.isScrollable(-1), BEEP); bind(["gg"], "Scroll to the beginning of output", function () { mow.scrollToPercent(null, 0); }); 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 bind([""], "Yank selection to clipboard", diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index ecec0dd2..b50dc070 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -693,7 +693,7 @@ var JavaScript = Module("javascript", { }); }, commandline: function initCommandLine(dactyl, modules, window) { - const { modes } = modules; + const { Buffer, modes } = modules; var REPL = Class("REPL", { init: function init(context) { @@ -741,7 +741,9 @@ var JavaScript = Module("javascript", { this.document, this); return this.rootNode; - }) + }), + + __noSuchMethod__: function (meth, args) Buffer[meth].apply(Buffer, [this.rootNode].concat(args)), }); modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, { @@ -816,9 +818,29 @@ var JavaScript = Module("javascript", { mappings: function initMappings(dactyl, modules, window) { const { mappings, modes } = modules; - mappings.add([modes.REPL], [""], - "Accept the current input", - function ({ self }) { self.accept(); }); + function bind() mappings.add.apply(mappings, + [[modes.REPL]].concat(Array.slice(arguments))) + + bind([""], "Accept the current input", + function ({ self }) { self.accept(); }); + + bind([""], "Scroll down one line", + function ({ self }) { self.repl.scrollVertical("lines", 1); }); + + bind([""], "Scroll up one line", + function ({ self }) { self.repl.scrollVertical("lines", -1); }); + + bind([""], "Scroll down half a page", + function ({ self }) { self.repl.scrollVertical("pages", .5); }); + + bind(["", ""], "Scroll down one page", + function ({ self }) { self.repl.scrollVertical("pages", 1); }); + + bind([""], "Scroll up half a page", + function ({ self }) { self.repl.scrollVertical("pages", -.5); }); + + bind(["", ""], "Scroll up half a page", + function ({ self }) { self.repl.scrollVertical("pages", -1); }); }, options: function (dactyl, modules, window) { modules.options.add(["jsdebugger", "jsd"],