1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-23 07:53:32 +01:00

Cleanup motion maps somewhat. Add descriptions to other editor mappings.

This commit is contained in:
Kris Maglione
2011-02-19 15:46:34 -05:00
parent 4297b54d7a
commit 2583e32892

View File

@@ -99,7 +99,7 @@ var Editor = Module("editor", {
// cmd = y, d, c // cmd = y, d, c
// motion = b, 0, gg, G, etc. // motion = b, 0, gg, G, etc.
executeCommandWithMotion: function (cmd, motion, count) { selectMotion: function selectMotion(cmd, motion, count) {
// XXX: better as a precondition // XXX: better as a precondition
if (count == null) if (count == null)
count = 1; count = 1;
@@ -157,25 +157,6 @@ var Editor = Module("editor", {
dactyl.beep(); dactyl.beep();
return; return;
} }
switch (cmd) {
case "d":
this.executeCommand("cmd_delete", 1);
modes.pop(modes.TEXT_EDIT);
break;
case "c":
this.executeCommand("cmd_delete", 1);
modes.pop(modes.TEXT_EDIT);
modes.push(modes.INSERT);
break;
case "y":
this.executeCommand("cmd_copy", 1);
modes.pop(modes.TEXT_EDIT);
break;
default:
dactyl.beep();
}
}, },
// This function will move/select up to given "pos" // This function will move/select up to given "pos"
@@ -457,7 +438,7 @@ var Editor = Module("editor", {
mappings: function () { mappings: function () {
// add mappings for commands like h,j,k,l,etc. in CARET, VISUAL and TEXT_EDIT mode // add mappings for commands like h,j,k,l,etc. in CARET, VISUAL and TEXT_EDIT mode
function addMovementMap(keys, hasCount, caretModeMethod, caretModeArg, textEditCommand, visualTextEditCommand) { function addMovementMap(keys, description, hasCount, caretModeMethod, caretModeArg, textEditCommand, visualTextEditCommand) {
let extraInfo = {}; let extraInfo = {};
if (hasCount) if (hasCount)
extraInfo.count = true; extraInfo.count = true;
@@ -485,7 +466,7 @@ var Editor = Module("editor", {
} }
} }
mappings.add([modes.CARET], keys, "", mappings.add([modes.CARET], keys, description,
function ({ count }) { function ({ count }) {
if (!count) if (!count)
count = 1; count = 1;
@@ -495,7 +476,7 @@ var Editor = Module("editor", {
}, },
extraInfo); extraInfo);
mappings.add([modes.VISUAL], keys, "", mappings.add([modes.VISUAL], keys, description,
function ({ count }) { function ({ count }) {
if (!count) if (!count)
count = 1; count = 1;
@@ -515,7 +496,7 @@ var Editor = Module("editor", {
}, },
extraInfo); extraInfo);
mappings.add([modes.TEXT_EDIT], keys, "", mappings.add([modes.TEXT_EDIT], keys, description,
function ({ count }) { function ({ count }) {
if (!count) if (!count)
count = 1; count = 1;
@@ -535,15 +516,6 @@ var Editor = Module("editor", {
}); });
} }
function addMotionMap(key) {
mappings.add([modes.TEXT_EDIT], [key],
"Motion command",
function ({ count, motion }) {
editor.executeCommandWithMotion(key, motion, Math.max(count, 1));
},
{ count: true, motion: true });
}
function selectPreviousLine() { function selectPreviousLine() {
editor.executeCommand("cmd_selectLinePrevious"); editor.executeCommand("cmd_selectLinePrevious");
if ((modes.extended & modes.LINE) && !editor.selectedText()) if ((modes.extended & modes.LINE) && !editor.selectedText())
@@ -576,24 +548,41 @@ var Editor = Module("editor", {
move(true, /\S/)(editor_); move(true, /\S/)(editor_);
} }
// KEYS COUNT CARET TEXT_EDIT VISUAL_TEXT_EDIT // COUNT CARET TEXT_EDIT VISUAL_TEXT_EDIT
addMovementMap(["k", "<Up>"], true, "lineMove", false, "cmd_linePrevious", selectPreviousLine); addMovementMap(["k", "<Up>"], "Move up one line",
addMovementMap(["j", "<Down>", "<Return>"], true, "lineMove", true, "cmd_lineNext", selectNextLine); true, "lineMove", false, "cmd_linePrevious", selectPreviousLine);
addMovementMap(["h", "<Left>", "<BS>"], true, "characterMove", false, "cmd_charPrevious", "cmd_selectCharPrevious"); addMovementMap(["j", "<Down>", "<Return>"], "Move down one line",
addMovementMap(["l", "<Right>", "<Space>"], true, "characterMove", true, "cmd_charNext", "cmd_selectCharNext"); true, "lineMove", true, "cmd_lineNext", selectNextLine);
addMovementMap(["b", "<C-Left>"], true, "wordMove", false, "cmd_wordPrevious", "cmd_selectWordPrevious"); addMovementMap(["h", "<Left>", "<BS>"], "Move left one character",
addMovementMap(["w", "<C-Right>"], true, "wordMove", true, "cmd_wordNext", "cmd_selectWordNext"); true, "characterMove", false, "cmd_charPrevious", "cmd_selectCharPrevious");
addMovementMap(["B"], true, "wordMove", false, move(false, /\S/), select(false, /\S/)); addMovementMap(["l", "<Right>", "<Space>"], "Move right one character",
addMovementMap(["W"], true, "wordMove", true, move(true, /\S/), select(true, /\S/)); true, "characterMove", true, "cmd_charNext", "cmd_selectCharNext");
addMovementMap(["e"], true, "wordMove", false, move(true, /\W/), select(true, /\W/)); addMovementMap(["b", "<C-Left>"], "Move left one word",
addMovementMap(["E"], true, "wordMove", true, move(true, /\s/), select(true, /\s/)); true, "wordMove", false, "cmd_wordPrevious", "cmd_selectWordPrevious");
addMovementMap(["<C-f>", "<PageDown>"], true, "pageMove", true, "cmd_movePageDown", "cmd_selectNextPage"); addMovementMap(["w", "<C-Right>"], "Move right one word",
addMovementMap(["<C-b>", "<PageUp>"], true, "pageMove", false, "cmd_movePageUp", "cmd_selectPreviousPage"); true, "wordMove", true, "cmd_wordNext", "cmd_selectWordNext");
addMovementMap(["gg", "<C-Home>"], false, "completeMove", false, "cmd_moveTop", "cmd_selectTop"); addMovementMap(["B"], "Move left to the previous white space",
addMovementMap(["G", "<C-End>"], false, "completeMove", true, "cmd_moveBottom", "cmd_selectBottom"); true, "wordMove", false, move(false, /\S/), select(false, /\S/));
addMovementMap(["0", "<Home>"], false, "intraLineMove", false, "cmd_beginLine", "cmd_selectBeginLine"); addMovementMap(["W"], "Move right to just beyond the next white space",
addMovementMap(["^"], false, "intraLineMove", false, beginLine, "cmd_selectBeginLine"); true, "wordMove", true, move(true, /\S/), select(true, /\S/));
addMovementMap(["$", "<End>"], false, "intraLineMove", true, "cmd_endLine" , "cmd_selectEndLine"); addMovementMap(["e"], "Move to the end of the current word",
true, "wordMove", false, move(true, /\W/), select(true, /\W/));
addMovementMap(["E"], "Move right to the next white space",
true, "wordMove", true, move(true, /\s/), select(true, /\s/));
addMovementMap(["<C-f>", "<PageDown>"], "Move down one page",
true, "pageMove", true, "cmd_movePageDown", "cmd_selectNextPage");
addMovementMap(["<C-b>", "<PageUp>"], "Move up one page",
true, "pageMove", false, "cmd_movePageUp", "cmd_selectPreviousPage");
addMovementMap(["gg", "<C-Home>"], "Move to the start of text",
false, "completeMove", false, "cmd_moveTop", "cmd_selectTop");
addMovementMap(["G", "<C-End>"], "Move to the end of text",
false, "completeMove", true, "cmd_moveBottom", "cmd_selectBottom");
addMovementMap(["0", "<Home>"], "Move to the beginning of the line",
false, "intraLineMove", false, "cmd_beginLine", "cmd_selectBeginLine");
addMovementMap(["^"], "Move to the first non-whitespace character of the line",
false, "intraLineMove", false, beginLine, "cmd_selectBeginLine");
addMovementMap(["$", "<End>"], "Move to the end of the current line",
false, "intraLineMove", true, "cmd_endLine" , "cmd_selectEndLine");
addBeginInsertModeMap(["i", "<Insert>"], []); addBeginInsertModeMap(["i", "<Insert>"], []);
addBeginInsertModeMap(["a"], ["cmd_charNext"]); addBeginInsertModeMap(["a"], ["cmd_charNext"]);
@@ -603,11 +592,27 @@ var Editor = Module("editor", {
addBeginInsertModeMap(["S"], ["cmd_deleteToEndOfLine", "cmd_deleteToBeginningOfLine"]); addBeginInsertModeMap(["S"], ["cmd_deleteToEndOfLine", "cmd_deleteToBeginningOfLine"]);
addBeginInsertModeMap(["C"], ["cmd_deleteToEndOfLine"]); addBeginInsertModeMap(["C"], ["cmd_deleteToEndOfLine"]);
addMotionMap("d"); // delete function addMotionMap(key, desc, cmd, mode) {
addMotionMap("c"); // change mappings.add([modes.TEXT_EDIT], [key],
addMotionMap("y"); // yank desc,
function ({ count, motion }) {
editor.selectMotion(key, motion, Math.max(count, 1));
if (callable(cmd))
cmd.call(events, Editor.getEditor(null));
else {
editor.executeCommand(cmd, 1);
modes.pop(modes.TEXT_EDIT);
}
if (mode)
modes.push(mode);
},
{ count: true, motion: true });
}
addMotionMap("d", "Delete motion", "cmd_delete");
addMotionMap("c", "Change motion", "cmd_delete", modes.INSERT);
addMotionMap("y", "Yank motion", "cmd_copy");
// insert mode mappings
mappings.add([modes.INPUT], mappings.add([modes.INPUT],
["<C-w>"], "Delete previous word", ["<C-w>"], "Delete previous word",
function () { editor.executeCommand("cmd_deleteWordBackward", 1); }); function () { editor.executeCommand("cmd_deleteWordBackward", 1); });
@@ -615,8 +620,9 @@ var Editor = Module("editor", {
mappings.add([modes.INPUT], mappings.add([modes.INPUT],
["<C-u>"], "Delete until beginning of current line", ["<C-u>"], "Delete until beginning of current line",
function () { function () {
// broken in FF3, deletes the whole line: // Deletes the whole line. What the hell.
// editor.executeCommand("cmd_deleteToBeginningOfLine", 1); // editor.executeCommand("cmd_deleteToBeginningOfLine", 1);
editor.executeCommand("cmd_selectBeginLine", 1); editor.executeCommand("cmd_selectBeginLine", 1);
if (Editor.getController().isCommandEnabled("cmd_delete")) if (Editor.getController().isCommandEnabled("cmd_delete"))
editor.executeCommand("cmd_delete", 1); editor.executeCommand("cmd_delete", 1);
@@ -642,14 +648,6 @@ var Editor = Module("editor", {
["<C-d>"], "Delete character to the right", ["<C-d>"], "Delete character to the right",
function () { editor.executeCommand("cmd_deleteCharForward", 1); }); function () { editor.executeCommand("cmd_deleteCharForward", 1); });
/*mappings.add([modes.INPUT],
["<C-Home>"], "Move cursor to beginning of text field",
function () { editor.executeCommand("cmd_moveTop", 1); });
mappings.add([modes.INPUT],
["<C-End>"], "Move cursor to end of text field",
function () { editor.executeCommand("cmd_moveBottom", 1); });*/
mappings.add([modes.INPUT], mappings.add([modes.INPUT],
["<S-Insert>"], "Insert clipboard/selection", ["<S-Insert>"], "Insert clipboard/selection",
function () { editor.pasteClipboard(); }); function () { editor.pasteClipboard(); });