add command_manager unit tests

This commit is contained in:
Fabian Jakobs 2011-11-11 11:10:37 +01:00
commit e910138acd
5 changed files with 204 additions and 96 deletions

View file

@ -45,286 +45,285 @@ var lang = require("../lib/lang");
function bindKey(win, mac) {
return {
win: win,
mac: mac,
sender: "editor"
mac: mac
};
}
exports.commands = [{
name: "selectall",
bindKey: bindKey("Ctrl-A", "Command-A"),
exec: function(env, args) { env.editor.selectAll(); }
exec: function(editor) { editor.selectAll(); }
}, {
name: "removeline",
bindKey: bindKey("Ctrl-D", "Command-D"),
exec: function(env, args) { env.editor.removeLines(); }
exec: function(editor) { editor.removeLines(); }
}, {
name: "gotoline",
bindKey: bindKey("Ctrl-L", "Command-L"),
exec: function(env, args) {
exec: function(editor) {
var line = parseInt(prompt("Enter line number:"));
if (!isNaN(line)) {
env.editor.gotoLine(line);
editor.gotoLine(line);
}
}
}, {
name: "togglecomment",
bindKey: bindKey("Ctrl-7", "Command-7"),
exec: function(env, args) { env.editor.toggleCommentLines(); }
exec: function(editor) { editor.toggleCommentLines(); }
}, {
name: "findnext",
bindKey: bindKey("Ctrl-K", "Command-G"),
exec: function(env, args) { env.editor.findNext(); }
exec: function(editor) { editor.findNext(); }
}, {
name: "findprevious",
bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
exec: function(env, args) { env.editor.findPrevious(); }
exec: function(editor) { editor.findPrevious(); }
}, {
name: "find",
bindKey: bindKey("Ctrl-F", "Command-F"),
exec: function(env, args) {
var needle = prompt("Find:", env.editor.getCopyText());
env.editor.find(needle);
exec: function(editor) {
var needle = prompt("Find:", editor.getCopyText());
editor.find(needle);
}
}, {
name: "replace",
bindKey: bindKey("Ctrl-R", "Command-Option-F"),
exec: function(env, args) {
var needle = prompt("Find:", env.editor.getCopyText());
exec: function(editor) {
var needle = prompt("Find:", editor.getCopyText());
if (!needle)
return;
var replacement = prompt("Replacement:");
if (!replacement)
return;
env.editor.replace(replacement, {needle: needle});
editor.replace(replacement, {needle: needle});
}
}, {
name: "replaceall",
bindKey: bindKey("Ctrl-Shift-R", "Command-Shift-Option-F"),
exec: function(env, args) {
exec: function(editor) {
var needle = prompt("Find:");
if (!needle)
return;
var replacement = prompt("Replacement:");
if (!replacement)
return;
env.editor.replaceAll(replacement, {needle: needle});
editor.replaceAll(replacement, {needle: needle});
}
}, {
name: "undo",
bindKey: bindKey("Ctrl-Z", "Command-Z"),
exec: function(env, args) { env.editor.undo(); }
exec: function(editor) { editor.undo(); }
}, {
name: "redo",
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
exec: function(env, args) { env.editor.redo(); }
exec: function(editor) { editor.redo(); }
}, {
name: "overwrite",
bindKey: bindKey("Insert", "Insert"),
exec: function(env, args) { env.editor.toggleOverwrite(); }
exec: function(editor) { editor.toggleOverwrite(); }
}, {
name: "copylinesup",
bindKey: bindKey("Ctrl-Alt-Up", "Command-Option-Up"),
exec: function(env, args) { env.editor.copyLinesUp(); }
exec: function(editor) { editor.copyLinesUp(); }
}, {
name: "movelinesup",
bindKey: bindKey("Alt-Up", "Option-Up"),
exec: function(env, args) { env.editor.moveLinesUp(); }
exec: function(editor) { editor.moveLinesUp(); }
}, {
name: "selecttostart",
bindKey: bindKey("Ctrl-Shift-Home|Alt-Shift-Up", "Command-Shift-Up"),
exec: function(env, args) { env.editor.getSelection().selectFileStart(); }
exec: function(editor) { editor.getSelection().selectFileStart(); }
}, {
name: "gotostart",
bindKey: bindKey("Ctrl-Home|Ctrl-Up", "Command-Home|Command-Up"),
exec: function(env, args) { env.editor.navigateFileStart(); }
exec: function(editor) { editor.navigateFileStart(); }
}, {
name: "selectup",
bindKey: bindKey("Shift-Up", "Shift-Up"),
exec: function(env, args) { env.editor.getSelection().selectUp(); }
exec: function(editor) { editor.getSelection().selectUp(); }
}, {
name: "golineup",
bindKey: bindKey("Up", "Up|Ctrl-P"),
exec: function(env, args) { env.editor.navigateUp(args.times); }
exec: function(editor, args) { editor.navigateUp(args.times); }
}, {
name: "copylinesdown",
bindKey: bindKey("Ctrl-Alt-Down", "Command-Option-Down"),
exec: function(env, args) { env.editor.copyLinesDown(); }
exec: function(editor) { editor.copyLinesDown(); }
}, {
name: "movelinesdown",
bindKey: bindKey("Alt-Down", "Option-Down"),
exec: function(env, args) { env.editor.moveLinesDown(); }
exec: function(editor) { editor.moveLinesDown(); }
}, {
name: "selecttoend",
bindKey: bindKey("Ctrl-Shift-End|Alt-Shift-Down", "Command-Shift-Down"),
exec: function(env, args) { env.editor.getSelection().selectFileEnd(); }
exec: function(editor) { editor.getSelection().selectFileEnd(); }
}, {
name: "gotoend",
bindKey: bindKey("Ctrl-End|Ctrl-Down", "Command-End|Command-Down"),
exec: function(env, args) { env.editor.navigateFileEnd(); }
exec: function(editor) { editor.navigateFileEnd(); }
}, {
name: "selectdown",
bindKey: bindKey("Shift-Down", "Shift-Down"),
exec: function(env, args) { env.editor.getSelection().selectDown(); }
exec: function(editor) { editor.getSelection().selectDown(); }
}, {
name: "golinedown",
bindKey: bindKey("Down", "Down|Ctrl-N"),
exec: function(env, args) { env.editor.navigateDown(args.times); }
exec: function(editor, args) { editor.navigateDown(args.times); }
}, {
name: "selectwordleft",
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
exec: function(env, args) { env.editor.getSelection().selectWordLeft(); }
exec: function(editor) { editor.getSelection().selectWordLeft(); }
}, {
name: "gotowordleft",
bindKey: bindKey("Ctrl-Left", "Option-Left"),
exec: function(env, args) { env.editor.navigateWordLeft(); }
exec: function(editor) { editor.navigateWordLeft(); }
}, {
name: "selecttolinestart",
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
exec: function(editor) { editor.getSelection().selectLineStart(); }
}, {
name: "gotolinestart",
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
exec: function(env, args) { env.editor.navigateLineStart(); }
exec: function(editor) { editor.navigateLineStart(); }
}, {
name: "selectleft",
bindKey: bindKey("Shift-Left", "Shift-Left"),
exec: function(env, args) { env.editor.getSelection().selectLeft(); }
exec: function(editor) { editor.getSelection().selectLeft(); }
}, {
name: "gotoleft",
bindKey: bindKey("Left", "Left|Ctrl-B"),
exec: function(env, args) { env.editor.navigateLeft(args.times); }
exec: function(editor, args) { editor.navigateLeft(args.times); }
}, {
name: "selectwordright",
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
exec: function(env, args) { env.editor.getSelection().selectWordRight(); }
exec: function(editor) { editor.getSelection().selectWordRight(); }
}, {
name: "gotowordright",
bindKey: bindKey("Ctrl-Right", "Option-Right"),
exec: function(env, args) { env.editor.navigateWordRight(); }
exec: function(editor) { editor.navigateWordRight(); }
}, {
name: "selecttolineend",
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
exec: function(editor) { editor.getSelection().selectLineEnd(); }
}, {
name: "gotolineend",
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
exec: function(env, args) { env.editor.navigateLineEnd(); }
exec: function(editor) { editor.navigateLineEnd(); }
}, {
name: "selectright",
bindKey: bindKey("Shift-Right", "Shift-Right"),
exec: function(env, args) { env.editor.getSelection().selectRight(); }
exec: function(editor) { editor.getSelection().selectRight(); }
}, {
name: "gotoright",
bindKey: bindKey("Right", "Right|Ctrl-F"),
exec: function(env, args) { env.editor.navigateRight(args.times); }
exec: function(editor, args) { editor.navigateRight(args.times); }
}, {
name: "selectpagedown",
bindKey: bindKey("Shift-PageDown", "Shift-PageDown"),
exec: function(env, args) { env.editor.selectPageDown(); }
exec: function(editor) { editor.selectPageDown(); }
}, {
name: "pagedown",
bindKey: bindKey(null, "PageDown"),
exec: function(env, args) { env.editor.scrollPageDown(); }
exec: function(editor) { editor.scrollPageDown(); }
}, {
name: "gotopagedown",
bindKey: bindKey("PageDown", "Option-PageDown|Ctrl-V"),
exec: function(env, args) { env.editor.gotoPageDown(); }
exec: function(editor) { editor.gotoPageDown(); }
}, {
name: "selectpageup",
bindKey: bindKey("Shift-PageUp", "Shift-PageUp"),
exec: function(env, args) { env.editor.selectPageUp(); }
exec: function(editor) { editor.selectPageUp(); }
}, {
name: "pageup",
bindKey: bindKey(null, "PageUp"),
exec: function(env, args) { env.editor.scrollPageUp(); }
exec: function(editor) { editor.scrollPageUp(); }
}, {
name: "gotopageup",
bindKey: bindKey("PageUp", "Option-PageUp"),
exec: function(env, args) { env.editor.gotoPageUp(); }
exec: function(editor) { editor.gotoPageUp(); }
}, {
name: "selectlinestart",
bindKey: bindKey("Shift-Home", "Shift-Home"),
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
exec: function(editor) { editor.getSelection().selectLineStart(); }
}, {
name: "selectlineend",
bindKey: bindKey("Shift-End", "Shift-End"),
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
exec: function(editor) { editor.getSelection().selectLineEnd(); }
}, {
name: "del",
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
exec: function(env, args) { env.editor.remove("right"); }
exec: function(editor) { editor.remove("right"); }
}, {
name: "backspace",
bindKey: bindKey(
"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
),
exec: function(env, args) { env.editor.remove("left"); }
exec: function(editor) { editor.remove("left"); }
}, {
name: "removetolinestart",
bindKey: bindKey("Alt-Backspace", "Option-Backspace"),
exec: function(env, args) { env.editor.removeToLineStart(); }
exec: function(editor) { editor.removeToLineStart(); }
}, {
name: "removetolineend",
bindKey: bindKey("Alt-Delete", "Ctrl-K"),
exec: function(env, args) { env.editor.removeToLineEnd(); }
exec: function(editor) { editor.removeToLineEnd(); }
}, {
name: "removewordleft",
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
exec: function(env, args) { env.editor.removeWordLeft(); }
exec: function(editor) { editor.removeWordLeft(); }
}, {
name: "removewordright",
bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
exec: function(env, args) { env.editor.removeWordRight(); }
exec: function(editor) { editor.removeWordRight(); }
}, {
name: "outdent",
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
exec: function(env, args) { env.editor.blockOutdent(); }
exec: function(editor) { editor.blockOutdent(); }
}, {
name: "indent",
bindKey: bindKey("Tab", "Tab"),
exec: function(env, args) { env.editor.indent(); }
exec: function(editor) { editor.indent(); }
}, {
name: "inserttext",
exec: function(env, args) {
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
exec: function(editor, args) {
editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
}
}, {
name: "centerselection",
bindKey: bindKey(null, "Ctrl-L"),
exec: function(env, args) { env.editor.centerSelection(); }
exec: function(editor) { editor.centerSelection(); }
}, {
name: "splitline",
bindKey: bindKey(null, "Ctrl-O"),
exec: function(env, args) { env.editor.splitLine(); }
exec: function(editor) { editor.splitLine(); }
}, {
name: "transposeletters",
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
exec: function(env, args) { env.editor.transposeLetters(); }
exec: function(editor) { editor.transposeLetters(); }
}, {
name: "fold",
bindKey: bindKey("Alt-L", "Alt-L"),
exec: function(env) {
env.editor.session.toggleFold(false);
exec: function(editor) {
editor.session.toggleFold(false);
}
}, {
name: "unfold",
bindKey: bindKey("Alt-Shift-L", "Alt-Shift-L"),
exec: function(env) {
env.editor.session.toggleFold(true);
exec: function(editor) {
editor.session.toggleFold(true);
}
}, {
name: "foldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.foldAll();
exec: function(editor) {
editor.session.foldAll();
}
}, {
name: "unfoldall",
bindKey: bindKey("Alt-Shift-0", "Alt-Shift-0"),
exec: function(env) {
env.editor.session.unFoldAll();
exec: function(editor) {
editor.session.unFoldAll();
}
}];