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

Replace weird mystery meat args of mapping actions with a proper object.

This commit is contained in:
Kris Maglione
2010-12-29 22:21:00 -05:00
parent f67a50147e
commit cb97f1cd25
12 changed files with 87 additions and 98 deletions

View File

@@ -95,12 +95,12 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL],
["<C-a>"], "Increment last number in URL",
function (count) { Browser.incrementURL(Math.max(count, 1)); },
function (args) { Browser.incrementURL(Math.max(args.count, 1)); },
{ count: true });
mappings.add([modes.NORMAL],
["<C-x>"], "Decrement last number in URL",
function (count) { Browser.incrementURL(-Math.max(count, 1)); },
function (args) { Browser.incrementURL(-Math.max(args.count, 1)); },
{ count: true });
mappings.add([modes.NORMAL], ["~"],
@@ -120,7 +120,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["gu"],
"Go to parent directory",
function (count) { Browser.climbUrlPath(Math.max(count, 1)); },
function (args) { Browser.climbUrlPath(Math.max(args.count, 1)); },
{ count: true });
mappings.add([modes.NORMAL], ["gU"],

View File

@@ -1507,9 +1507,9 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["."],
"Repeat the last key event",
function (count) {
function (args) {
if (mappings.repeat) {
for (let i in util.interruptibleRange(0, Math.max(count, 1), 100))
for (let i in util.interruptibleRange(0, Math.max(args.count, 1), 100))
mappings.repeat();
}
},
@@ -1526,22 +1526,22 @@ var Buffer = Module("buffer", {
// scrolling
mappings.add(myModes, ["j", "<Down>", "<C-e>"],
"Scroll document down",
function (count) { buffer.scrollLines(Math.max(count, 1)); },
function (args) { buffer.scrollLines(Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["k", "<Up>", "<C-y>"],
"Scroll document up",
function (count) { buffer.scrollLines(-Math.max(count, 1)); },
function (args) { buffer.scrollLines(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, dactyl.has("mail") ? ["h"] : ["h", "<Left>"],
"Scroll document to the left",
function (count) { buffer.scrollColumns(-Math.max(count, 1)); },
function (args) { buffer.scrollColumns(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, dactyl.has("mail") ? ["l"] : ["l", "<Right>"],
"Scroll document to the right",
function (count) { buffer.scrollColumns(Math.max(count, 1)); },
function (args) { buffer.scrollColumns(Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["0", "^"],
@@ -1554,63 +1554,63 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["gg", "<Home>"],
"Go to the top of the document",
function (count) { buffer.scrollToPercent(null, count != null ? count : 0); },
function (args) { buffer.scrollToPercent(null, args.count != null ? args.count : 0); },
{ count: true });
mappings.add(myModes, ["G", "<End>"],
"Go to the end of the document",
function (count) { buffer.scrollToPercent(null, count != null ? count : 100); },
function (args) { buffer.scrollToPercent(null, args.count != null ? args.count : 100); },
{ count: true });
mappings.add(myModes, ["%"],
"Scroll to {count} percent of the document",
function (count) {
dactyl.assert(count > 0 && count <= 100);
function (args) {
dactyl.assert(args.count > 0 && count <= 100);
buffer.scrollToPercent(null, count);
},
{ count: true });
mappings.add(myModes, ["<C-d>"],
"Scroll window downwards in the buffer",
function (count) { buffer._scrollByScrollSize(count, true); },
function (args) { buffer._scrollByScrollSize(args.count, true); },
{ count: true });
mappings.add(myModes, ["<C-u>"],
"Scroll window upwards in the buffer",
function (count) { buffer._scrollByScrollSize(count, false); },
function (args) { buffer._scrollByScrollSize(args.count, false); },
{ count: true });
mappings.add(myModes, ["<C-b>", "<PageUp>", "<S-Space>"],
"Scroll up a full page",
function (count) { buffer.scrollPages(-Math.max(count, 1)); },
function (args) { buffer.scrollPages(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["<C-f>", "<PageDown>", "<Space>"],
"Scroll down a full page",
function (count) { buffer.scrollPages(Math.max(count, 1)); },
function (args) { buffer.scrollPages(Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["]f"],
"Focus next frame",
function (count) { buffer.shiftFrameFocus(Math.max(count, 1)); },
function (args) { buffer.shiftFrameFocus(Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["[f"],
"Focus previous frame",
function (count) { buffer.shiftFrameFocus(-Math.max(count, 1)); },
function (args) { buffer.shiftFrameFocus(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes, ["]]"],
"Follow the link labeled 'next' or '>' if it exists",
function (count) {
buffer.findLink("next", options["nextpattern"], (count || 1) - 1, true);
function (args) {
buffer.findLink("next", options["nextpattern"], (args.count || 1) - 1, true);
},
{ count: true });
mappings.add(myModes, ["[["],
"Follow the link labeled 'prev', 'previous' or '<' if it exists",
function (count) {
buffer.findLink("previous", options["previouspattern"], (count || 1) - 1, true);
function (args) {
buffer.findLink("previous", options["previouspattern"], (args.count || 1) - 1, true);
},
{ count: true });
@@ -1624,10 +1624,10 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["gi"],
"Focus last used input field",
function (count) {
function (args) {
let elem = buffer.lastInputField;
if (count >= 1 || !elem || !Events.isContentNode(elem)) {
if (args.count >= 1 || !elem || !Events.isContentNode(elem)) {
let xpath = ["frame", "iframe", "input", "textarea[not(@disabled) and not(@readonly)]"];
let frames = buffer.allFrames(null, true);
@@ -1647,7 +1647,7 @@ var Buffer = Module("buffer", {
});
dactyl.assert(elements.length > 0);
elem = elements[Math.constrain(count, 1, elements.length) - 1];
elem = elements[Math.constrain(args.count, 1, elements.length) - 1];
}
buffer.focusElement(elem);
util.scrollIntoView(elem);
@@ -1699,59 +1699,58 @@ var Buffer = Module("buffer", {
// zooming
mappings.add(myModes, ["zi", "+"],
"Enlarge text zoom of current web page",
function (count) { buffer.zoomIn(Math.max(count, 1), false); },
function (args) { buffer.zoomIn(Math.max(args.count, 1), false); },
{ count: true });
mappings.add(myModes, ["zm"],
"Enlarge text zoom of current web page by a larger amount",
function (count) { buffer.zoomIn(Math.max(count, 1) * 3, false); },
function (args) { buffer.zoomIn(Math.max(args.count, 1) * 3, false); },
{ count: true });
mappings.add(myModes, ["zo", "-"],
"Reduce text zoom of current web page",
function (count) { buffer.zoomOut(Math.max(count, 1), false); },
function (args) { buffer.zoomOut(Math.max(args.count, 1), false); },
{ count: true });
mappings.add(myModes, ["zr"],
"Reduce text zoom of current web page by a larger amount",
function (count) { buffer.zoomOut(Math.max(count, 1) * 3, false); },
function (args) { buffer.zoomOut(Math.max(args.count, 1) * 3, false); },
{ count: true });
mappings.add(myModes, ["zz"],
"Set text zoom value of current web page",
function (count) { Buffer.setZoom(count > 1 ? count : 100, false); },
function (args) { Buffer.setZoom(args.count > 1 ? count : 100, false); },
{ count: true });
mappings.add(myModes, ["ZI", "zI"],
"Enlarge full zoom of current web page",
function (count) { buffer.zoomIn(Math.max(count, 1), true); },
function (args) { buffer.zoomIn(Math.max(args.count, 1), true); },
{ count: true });
mappings.add(myModes, ["ZM", "zM"],
"Enlarge full zoom of current web page by a larger amount",
function (count) { buffer.zoomIn(Math.max(count, 1) * 3, true); },
function (args) { buffer.zoomIn(Math.max(args.count, 1) * 3, true); },
{ count: true });
mappings.add(myModes, ["ZO", "zO"],
"Reduce full zoom of current web page",
function (count) { buffer.zoomOut(Math.max(count, 1), true); },
function (args) { buffer.zoomOut(Math.max(args.count, 1), true); },
{ count: true });
mappings.add(myModes, ["ZR", "zR"],
"Reduce full zoom of current web page by a larger amount",
function (count) { buffer.zoomOut(Math.max(count, 1) * 3, true); },
function (args) { buffer.zoomOut(Math.max(args.count, 1) * 3, true); },
{ count: true });
mappings.add(myModes, ["zZ"],
"Set full zoom value of current web page",
function (count) { Buffer.setZoom(count > 1 ? count : 100, true); },
function (args) { Buffer.setZoom(args.count > 1 ? args.count : 100, true); },
{ count: true });
// page info
mappings.add(myModes, ["<C-g>"],
"Print the current file name",
function (count) { buffer.showPageInfo(false); },
{ count: true });
function () { buffer.showPageInfo(false); })
mappings.add(myModes, ["g<C-g>"],
"Print file information",

View File

@@ -935,7 +935,6 @@ var CommandLine = Module("commandline", {
}
else if (event.type == "keypress") {
let key = events.toString(event);
util.dump("keypress", key, Events.isEscape(event));
if (this._completions)
this._completions.previewClear();
if (!this.currentExtendedMode)

View File

@@ -335,8 +335,7 @@ var Command = Class("Command", {
case "-keys":
let silent = args["-silent"];
rhs = events.canonicalKeys(rhs, true);
var action = function action(count) events.feedkeys(action.macro({ count: count || "" }),
noremap, silent);
var action = function action(args) events.feedkeys(action.macro(args), noremap, silent);
action.macro = util.compileMacro(rhs, true);
break;
case "-ex":
@@ -1527,9 +1526,9 @@ var Commands = Module("commands", {
mappings: function () {
mappings.add(config.browserModes,
["@:"], "Repeat the last Ex command",
function (count) {
function (args) {
if (commands.repeat) {
for (let i in util.interruptibleRange(0, Math.max(count, 1), 100))
for (let i in util.interruptibleRange(0, Math.max(args.count, 1), 100))
dactyl.execute(commands.repeat);
}
else

View File

@@ -431,7 +431,7 @@ var Editor = Module("editor", {
}
mappings.add([modes.CARET], keys, "",
function (count) {
function ({ count }) {
if (!count)
count = 1;
@@ -441,7 +441,7 @@ var Editor = Module("editor", {
extraInfo);
mappings.add([modes.VISUAL], keys, "",
function (count) {
function ({ count }) {
if (!count)
count = 1;
@@ -460,7 +460,7 @@ var Editor = Module("editor", {
extraInfo);
mappings.add([modes.TEXT_EDIT], keys, "",
function (count) {
function ({ count }) {
if (!count)
count = 1;
@@ -482,7 +482,7 @@ var Editor = Module("editor", {
function addMotionMap(key) {
mappings.add([modes.TEXT_EDIT], [key],
"Motion command",
function (motion, count) {
function ({ count, motion }) {
editor.executeCommandWithMotion(key, motion, Math.max(count, 1));
},
{ count: true, motion: true });
@@ -597,16 +597,16 @@ var Editor = Module("editor", {
// text edit mode
mappings.add([modes.TEXT_EDIT],
["u"], "Undo changes",
function (count) {
editor.executeCommand("cmd_undo", Math.max(count, 1));
function (args) {
editor.executeCommand("cmd_undo", Math.max(args.count, 1));
editor.unselectText();
},
{ count: true });
mappings.add([modes.TEXT_EDIT],
["<C-r>"], "Redo undone changes",
function (count) {
editor.executeCommand("cmd_redo", Math.max(count, 1));
function (args) {
editor.executeCommand("cmd_redo", Math.max(args.count, 1));
editor.unselectText();
},
{ count: true });
@@ -634,18 +634,18 @@ var Editor = Module("editor", {
mappings.add([modes.TEXT_EDIT],
["X"], "Delete character to the left",
function (count) { editor.executeCommand("cmd_deleteCharBackward", Math.max(count, 1)); },
function (args) { editor.executeCommand("cmd_deleteCharBackward", Math.max(args.count, 1)); },
{ count: true });
mappings.add([modes.TEXT_EDIT],
["x"], "Delete character to the right",
function (count) { editor.executeCommand("cmd_deleteCharForward", Math.max(count, 1)); },
function (args) { editor.executeCommand("cmd_deleteCharForward", Math.max(args.count, 1)); },
{ count: true });
// visual mode
mappings.add([modes.CARET, modes.TEXT_EDIT],
["v"], "Start visual mode",
function (count) { modes.push(modes.VISUAL); });
function () { modes.push(modes.VISUAL); });
mappings.add([modes.VISUAL],
["v", "V"], "End visual mode",
@@ -687,7 +687,7 @@ var Editor = Module("editor", {
mappings.add([modes.VISUAL, modes.TEXT_EDIT],
["p"], "Paste clipboard contents",
function (count) {
function ({ count }) {
dactyl.assert(!editor.isCaret);
if (!count)
count = 1;
@@ -700,7 +700,7 @@ var Editor = Module("editor", {
// finding characters
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
["f"], "Move to a character on the current line after the cursor",
function (count, arg) {
function ({ arg, count }) {
let pos = editor.findCharForward(arg, Math.max(count, 1));
if (pos >= 0)
editor.moveToPosition(pos, true, dactyl.mode == modes.VISUAL);
@@ -709,7 +709,7 @@ var Editor = Module("editor", {
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
["F"], "Move to a character on the current line before the cursor",
function (count, arg) {
function ({ arg, count }) {
let pos = editor.findCharBackward(arg, Math.max(count, 1));
if (pos >= 0)
editor.moveToPosition(pos, false, dactyl.mode == modes.VISUAL);
@@ -718,7 +718,7 @@ var Editor = Module("editor", {
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
["t"], "Move before a character on the current line",
function (count, arg) {
function ({ arg, count }) {
let pos = editor.findCharForward(arg, Math.max(count, 1));
if (pos >= 0)
editor.moveToPosition(pos - 1, true, dactyl.mode == modes.VISUAL);
@@ -727,7 +727,7 @@ var Editor = Module("editor", {
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
["T"], "Move before a character on the current line, backwards",
function (count, arg) {
function ({ arg, count }) {
let pos = editor.findCharBackward(arg, Math.max(count, 1));
if (pos >= 0)
editor.moveToPosition(pos + 1, false, dactyl.mode == modes.VISUAL);
@@ -737,7 +737,7 @@ var Editor = Module("editor", {
// text edit and visual mode
mappings.add([modes.TEXT_EDIT, modes.VISUAL],
["~"], "Switch case of the character under the cursor and move the cursor to the right",
function (count) {
function ({ count }) {
if (modes.main == modes.VISUAL)
count = Editor.getEditor().selectionEnd - Editor.getEditor().selectionStart;
count = Math.max(count, 1);

View File

@@ -1253,7 +1253,7 @@ var Events = Module("events", {
mappings.add([modes.NORMAL, modes.TEXT_AREA, modes.PLAYER].filter(util.identity),
["@"], "Play a macro",
function (count, arg) {
function ({ arg, count }) {
count = Math.max(count, 1);
while (count-- && events.playMacro(arg))
;

View File

@@ -1050,12 +1050,12 @@ var Hints = Module("hints", {
mappings.add(myModes, [";"],
"Start an extended hint mode",
function (count) { hints.open(";", { count: count }); },
function ({ count }) { hints.open(";", { count: count }); },
{ count: true });
mappings.add(myModes, ["g;"],
"Start an extended hint mode and stay there until <Esc> is pressed",
function (count) { hints.open("g;", { continue: true, count: count }); },
function ({ count }) { hints.open("g;", { continue: true, count: count }); },
{ count: true });
function update(followFirst) {

View File

@@ -274,22 +274,22 @@ var History = Module("history", {
mappings.add(myModes,
["<C-o>"], "Go to an older position in the jump list",
function (count) { history.stepTo(-Math.max(count, 1)); },
function (args) { history.stepTo(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes,
["<C-i>"], "Go to a newer position in the jump list",
function (count) { history.stepTo(Math.max(count, 1)); },
function (args) { history.stepTo(Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes,
["H", "<A-Left>", "<M-Left>"], "Go back in the browser history",
function (count) { history.stepTo(-Math.max(count, 1)); },
function (args) { history.stepTo(-Math.max(args.count, 1)); },
{ count: true });
mappings.add(myModes,
["L", "<A-Right>", "<M-Right>"], "Go forward in the browser history",
function (count) { history.stepTo(Math.max(count, 1)); },
function (args) { history.stepTo(Math.max(args.count, 1)); },
{ count: true });
}
});

View File

@@ -105,18 +105,10 @@ var Map = Class("Map", {
* mapping. E.g. "a" for "ma"
*/
execute: function (motion, count, argument, command) {
let args = [];
if (this.motion)
args.push(motion);
if (this.count)
args.push(count);
if (this.arg)
args.push(argument);
args.push(command);
let args = { count: count, arg: argument, motion: motion, command: command };
let self = this;
function repeat() self.action.apply(self, args);
function repeat() self.action(args)
if (this.names[0] != ".") // FIXME: Kludge.
mappings.repeat = repeat;
@@ -374,7 +366,7 @@ var Mappings = Module("mappings", {
else {
mappings.addUserMap(mapmodes, [lhs],
args["-description"],
Command.bindMacro(args, "-keys", ["count"]),
Command.bindMacro(args, "-keys", function (params) params),
{
count: args["-count"],
noremap: args["-builtin"],

View File

@@ -200,7 +200,7 @@ var Marks = Module("marks", {
mappings.add(myModes,
["m"], "Set mark at the cursor position",
function (arg) {
function ({ arg }) {
dactyl.assert(/^[a-zA-Z]$/.test(arg));
marks.add(arg);
},
@@ -208,7 +208,7 @@ var Marks = Module("marks", {
mappings.add(myModes,
["'", "`"], "Jump to the mark in the current buffer",
function (arg) { marks.jumpTo(arg); },
function (args) { marks.jumpTo(args.arg); },
{ arg: true });
},

View File

@@ -192,17 +192,17 @@ var QuickMarks = Module("quickmarks", {
mappings.add(myModes,
["go"], "Jump to a QuickMark",
function (arg) { quickmarks.jumpTo(arg, dactyl.CURRENT_TAB); },
function (args) { quickmarks.jumpTo(args.arg, dactyl.CURRENT_TAB); },
{ arg: true });
mappings.add(myModes,
["gn"], "Jump to a QuickMark in a new tab",
function (arg) { quickmarks.jumpTo(arg, { from: "quickmark", where: dactyl.NEW_TAB }); },
function (args) { quickmarks.jumpTo(args.arg, { from: "quickmark", where: dactyl.NEW_TAB }); },
{ arg: true });
mappings.add(myModes,
["M"], "Add new QuickMark for current URL",
function (arg) {
function ({ arg }) {
dactyl.assert(/^[a-zA-Z0-9]$/.test(arg));
quickmarks.add(arg, buffer.URL);
},

View File

@@ -878,15 +878,15 @@ var Tabs = Module("tabs", {
mappings: function () {
mappings.add([modes.NORMAL], ["g0", "g^"],
"Go to the first tab",
function (count) { tabs.select(0); });
function () { tabs.select(0); });
mappings.add([modes.NORMAL], ["g$"],
"Go to the last tab",
function (count) { tabs.select("$"); });
function () { tabs.select("$"); });
mappings.add([modes.NORMAL], ["gt"],
"Go to the next tab",
function (count) {
function ({ count }) {
if (count != null)
tabs.select(count - 1, false);
else
@@ -896,18 +896,18 @@ var Tabs = Module("tabs", {
mappings.add([modes.NORMAL], ["<C-n>", "<C-Tab>", "<C-PageDown>"],
"Go to the next tab",
function (count) { tabs.select("+" + (count || 1), true); },
function ({ count }) { tabs.select("+" + (count || 1), true); },
{ count: true });
mappings.add([modes.NORMAL], ["gT", "<C-p>", "<C-S-Tab>", "<C-PageUp>"],
"Go to previous tab",
function (count) { tabs.select("-" + (count || 1), true); },
function ({ count }) { tabs.select("-" + (count || 1), true); },
{ count: true });
if (config.hasTabbrowser) {
mappings.add([modes.NORMAL], ["b"],
"Open a prompt to switch buffers",
function (count) {
function ({ count }) {
if (count != null)
tabs.switchTo(String(count));
else
@@ -921,39 +921,39 @@ var Tabs = Module("tabs", {
mappings.add([modes.NORMAL], ["d"],
"Delete current buffer",
function (count) { tabs.remove(tabs.getTab(), count, false); },
function ({ count }) { tabs.remove(tabs.getTab(), count, false); },
{ count: true });
mappings.add([modes.NORMAL], ["D"],
"Delete current buffer, focus tab to the left",
function (count) { tabs.remove(tabs.getTab(), count, true); },
function ({ count }) { tabs.remove(tabs.getTab(), count, true); },
{ count: true });
mappings.add([modes.NORMAL], ["gb"],
"Repeat last :buffer[!] command",
function (count) { tabs.switchTo(null, null, count, false); },
function ({ count }) { tabs.switchTo(null, null, count, false); },
{ count: true });
mappings.add([modes.NORMAL], ["gB"],
"Repeat last :buffer[!] command in reverse direction",
function (count) { tabs.switchTo(null, null, count, true); },
function ({ count }) { tabs.switchTo(null, null, count, true); },
{ count: true });
// TODO: feature dependencies - implies "session"?
if (dactyl.has("tabs_undo")) {
mappings.add([modes.NORMAL], ["u"],
"Undo closing of a tab",
function (count) { ex.undo({ "#": count }); },
function ({ count }) { ex.undo({ "#": count }); },
{ count: true });
}
mappings.add([modes.NORMAL], ["<C-^>", "<C-6>"],
"Select the alternate tab or the [count]th tab",
function (count) {
if (count < 1)
tabs.selectAlternateTab();
function ({ count }) {
if (count != null)
tabs.switchTo(String(count), false);
else
tabs.switchTo(count.toString(), false);
tabs.selectAlternateTab();
},
{ count: true });
}