command_manager is no longer a singleton
This commit is contained in:
parent
8d0e1784e2
commit
c417dcd4e6
5 changed files with 136 additions and 180 deletions
|
|
@ -41,7 +41,6 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
exports.launch = function(env) {
|
exports.launch = function(env) {
|
||||||
var commands = require("ace/commands/command_manager");
|
|
||||||
var event = require("pilot/event");
|
var event = require("pilot/event");
|
||||||
var Range = require("ace/range").Range;
|
var Range = require("ace/range").Range;
|
||||||
var Editor = require("ace/editor").Editor;
|
var Editor = require("ace/editor").Editor;
|
||||||
|
|
@ -554,6 +553,8 @@ exports.launch = function(env) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Fake-Save, works from the editor and the command line.
|
// Fake-Save, works from the editor and the command line.
|
||||||
|
var commands = env.editor.commands;
|
||||||
|
|
||||||
commands.addCommand({
|
commands.addCommand({
|
||||||
name: "save",
|
name: "save",
|
||||||
bindKey: {
|
bindKey: {
|
||||||
|
|
|
||||||
|
|
@ -3,70 +3,82 @@ define(function(require, exports, module) {
|
||||||
var keyUtil = require('pilot/keys');
|
var keyUtil = require('pilot/keys');
|
||||||
var useragent = require('pilot/useragent');
|
var useragent = require('pilot/useragent');
|
||||||
|
|
||||||
var commands = {};
|
var CommandManager = function(commands) {
|
||||||
var commmandKeyBinding = {};
|
this.commands = {};
|
||||||
|
this.commmandKeyBinding = {};
|
||||||
exports.addCommand = function(command) {
|
|
||||||
commands[command.name] = command;
|
if (commands)
|
||||||
|
commands.forEach(this.addCommand, this);
|
||||||
if (command.bindKey) {
|
|
||||||
buildKeyHash(command);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var platform = useragent.isMac ? "mac" : "win";
|
(function() {
|
||||||
function buildKeyHash(command) {
|
|
||||||
var binding = command.bindKey;
|
|
||||||
var key = binding[platform];
|
|
||||||
var ckb = commmandKeyBinding;
|
|
||||||
|
|
||||||
if(!binding[platform]) {
|
this.addCommand = function(command) {
|
||||||
return;
|
this.commands[command.name] = command;
|
||||||
}
|
|
||||||
|
if (command.bindKey) {
|
||||||
|
this._buildKeyHash(command);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var platform = useragent.isMac ? "mac" : "win";
|
||||||
|
|
||||||
key.split("|").forEach(function(keyPart) {
|
this._buildKeyHash = function(command) {
|
||||||
var binding = parseKeys(keyPart, command);
|
var binding = command.bindKey;
|
||||||
var hashId = binding.hashId;
|
var key = binding[platform];
|
||||||
(ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
|
var ckb = this.commmandKeyBinding;
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseKeys(keys, val, ret) {
|
if(!binding[platform]) {
|
||||||
var key;
|
return;
|
||||||
var hashId = 0;
|
}
|
||||||
var parts = splitSafe(keys, "\\-", null, true);
|
|
||||||
|
|
||||||
for (var i=0, l = parts.length; i < l; i++) {
|
|
||||||
if (keyUtil.KEY_MODS[parts[i]])
|
|
||||||
hashId = hashId | keyUtil.KEY_MODS[parts[i]];
|
|
||||||
else
|
|
||||||
key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
key.split("|").forEach(function(keyPart) {
|
||||||
key: key,
|
var binding = parseKeys(keyPart, command);
|
||||||
hashId: hashId
|
var hashId = binding.hashId;
|
||||||
}
|
(ckb[hashId] || (ckb[hashId] = {}))[binding.key] = command;
|
||||||
}
|
});
|
||||||
|
|
||||||
function splitSafe(s, separator, limit, bLowerCase) {
|
|
||||||
return (bLowerCase && s.toLowerCase() || s)
|
|
||||||
.replace(/(?:^\s+|\n|\s+$)/g, "")
|
|
||||||
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.findKeyCommand = function findKeyCommand(env, hashId, textOrKey) {
|
|
||||||
// Convert keyCode to the string representation.
|
|
||||||
if (typeof textOrKey == "number") {
|
|
||||||
textOrKey = keyUtil.keyCodeToString(textOrKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ckbr = commmandKeyBinding;
|
|
||||||
return ckbr[hashId] && ckbr[hashId][textOrKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.exec = function(command, env, args) {
|
function parseKeys(keys, val, ret) {
|
||||||
command.exec(env, args || {});
|
var key;
|
||||||
};
|
var hashId = 0;
|
||||||
|
var parts = splitSafe(keys, "\\-", null, true);
|
||||||
|
|
||||||
|
for (var i=0, l = parts.length; i < l; i++) {
|
||||||
|
if (keyUtil.KEY_MODS[parts[i]])
|
||||||
|
hashId = hashId | keyUtil.KEY_MODS[parts[i]];
|
||||||
|
else
|
||||||
|
key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: key,
|
||||||
|
hashId: hashId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitSafe(s, separator, limit, bLowerCase) {
|
||||||
|
return (bLowerCase && s.toLowerCase() || s)
|
||||||
|
.replace(/(?:^\s+|\n|\s+$)/g, "")
|
||||||
|
.split(new RegExp("[\\s ]*" + separator + "[\\s ]*", "g"), limit || 999);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.findKeyCommand = function findKeyCommand(env, hashId, textOrKey) {
|
||||||
|
// Convert keyCode to the string representation.
|
||||||
|
if (typeof textOrKey == "number") {
|
||||||
|
textOrKey = keyUtil.keyCodeToString(textOrKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ckbr = this.commmandKeyBinding;
|
||||||
|
return ckbr[hashId] && ckbr[hashId][textOrKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.exec = function(command, env, args) {
|
||||||
|
command.exec(env, args || {});
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(CommandManager.prototype);
|
||||||
|
|
||||||
|
exports.CommandManager = CommandManager;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var lang = require("pilot/lang");
|
var lang = require("pilot/lang");
|
||||||
var commands = require("ace/commands/command_manager");
|
|
||||||
|
|
||||||
function bindKey(win, mac) {
|
function bindKey(win, mac) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -51,22 +50,15 @@ function bindKey(win, mac) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
commands.addCommand({
|
exports.commands = [{
|
||||||
name: "null",
|
|
||||||
exec: function(env, args) { }
|
|
||||||
});
|
|
||||||
|
|
||||||
commands.addCommand({
|
|
||||||
name: "selectall",
|
name: "selectall",
|
||||||
bindKey: bindKey("Ctrl-A", "Command-A"),
|
bindKey: bindKey("Ctrl-A", "Command-A"),
|
||||||
exec: function(env, args) { env.editor.selectAll(); }
|
exec: function(env, args) { env.editor.selectAll(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "removeline",
|
name: "removeline",
|
||||||
bindKey: bindKey("Ctrl-D", "Command-D"),
|
bindKey: bindKey("Ctrl-D", "Command-D"),
|
||||||
exec: function(env, args) { env.editor.removeLines(); }
|
exec: function(env, args) { env.editor.removeLines(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotoline",
|
name: "gotoline",
|
||||||
bindKey: bindKey("Ctrl-L", "Command-L"),
|
bindKey: bindKey("Ctrl-L", "Command-L"),
|
||||||
exec: function(env, args) {
|
exec: function(env, args) {
|
||||||
|
|
@ -75,31 +67,26 @@ commands.addCommand({
|
||||||
env.editor.gotoLine(line);
|
env.editor.gotoLine(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "togglecomment",
|
name: "togglecomment",
|
||||||
bindKey: bindKey("Ctrl-7", "Command-7"),
|
bindKey: bindKey("Ctrl-7", "Command-7"),
|
||||||
exec: function(env, args) { env.editor.toggleCommentLines(); }
|
exec: function(env, args) { env.editor.toggleCommentLines(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "findnext",
|
name: "findnext",
|
||||||
bindKey: bindKey("Ctrl-K", "Command-G"),
|
bindKey: bindKey("Ctrl-K", "Command-G"),
|
||||||
exec: function(env, args) { env.editor.findNext(); }
|
exec: function(env, args) { env.editor.findNext(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "findprevious",
|
name: "findprevious",
|
||||||
bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
|
bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
|
||||||
exec: function(env, args) { env.editor.findPrevious(); }
|
exec: function(env, args) { env.editor.findPrevious(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "find",
|
name: "find",
|
||||||
bindKey: bindKey("Ctrl-F", "Command-F"),
|
bindKey: bindKey("Ctrl-F", "Command-F"),
|
||||||
exec: function(env, args) {
|
exec: function(env, args) {
|
||||||
var needle = prompt("Find:");
|
var needle = prompt("Find:");
|
||||||
env.editor.find(needle);
|
env.editor.find(needle);
|
||||||
}
|
}
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "replace",
|
name: "replace",
|
||||||
bindKey: bindKey("Ctrl-R", "Command-Option-F"),
|
bindKey: bindKey("Ctrl-R", "Command-Option-F"),
|
||||||
exec: function(env, args) {
|
exec: function(env, args) {
|
||||||
|
|
@ -111,8 +98,7 @@ commands.addCommand({
|
||||||
return;
|
return;
|
||||||
env.editor.replace(replacement, {needle: needle});
|
env.editor.replace(replacement, {needle: needle});
|
||||||
}
|
}
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "replaceall",
|
name: "replaceall",
|
||||||
bindKey: bindKey("Ctrl-Shift-R", "Command-Shift-Option-F"),
|
bindKey: bindKey("Ctrl-Shift-R", "Command-Shift-Option-F"),
|
||||||
exec: function(env, args) {
|
exec: function(env, args) {
|
||||||
|
|
@ -124,245 +110,198 @@ commands.addCommand({
|
||||||
return;
|
return;
|
||||||
env.editor.replaceAll(replacement, {needle: needle});
|
env.editor.replaceAll(replacement, {needle: needle});
|
||||||
}
|
}
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "undo",
|
name: "undo",
|
||||||
bindKey: bindKey("Ctrl-Z", "Command-Z"),
|
bindKey: bindKey("Ctrl-Z", "Command-Z"),
|
||||||
exec: function(env, args) { env.editor.undo(); }
|
exec: function(env, args) { env.editor.undo(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "redo",
|
name: "redo",
|
||||||
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
|
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
|
||||||
exec: function(env, args) { env.editor.redo(); }
|
exec: function(env, args) { env.editor.redo(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "overwrite",
|
name: "overwrite",
|
||||||
bindKey: bindKey("Insert", "Insert"),
|
bindKey: bindKey("Insert", "Insert"),
|
||||||
exec: function(env, args) { env.editor.toggleOverwrite(); }
|
exec: function(env, args) { env.editor.toggleOverwrite(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "copylinesup",
|
name: "copylinesup",
|
||||||
bindKey: bindKey("Ctrl-Alt-Up", "Command-Option-Up"),
|
bindKey: bindKey("Ctrl-Alt-Up", "Command-Option-Up"),
|
||||||
exec: function(env, args) { env.editor.copyLinesUp(); }
|
exec: function(env, args) { env.editor.copyLinesUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "movelinesup",
|
name: "movelinesup",
|
||||||
bindKey: bindKey("Alt-Up", "Option-Up"),
|
bindKey: bindKey("Alt-Up", "Option-Up"),
|
||||||
exec: function(env, args) { env.editor.moveLinesUp(); }
|
exec: function(env, args) { env.editor.moveLinesUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selecttostart",
|
name: "selecttostart",
|
||||||
bindKey: bindKey("Ctrl-Shift-Home|Alt-Shift-Up", "Command-Shift-Up"),
|
bindKey: bindKey("Ctrl-Shift-Home|Alt-Shift-Up", "Command-Shift-Up"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectFileStart(); }
|
exec: function(env, args) { env.editor.getSelection().selectFileStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotostart",
|
name: "gotostart",
|
||||||
bindKey: bindKey("Ctrl-Home|Ctrl-Up", "Command-Home|Command-Up"),
|
bindKey: bindKey("Ctrl-Home|Ctrl-Up", "Command-Home|Command-Up"),
|
||||||
exec: function(env, args) { env.editor.navigateFileStart(); }
|
exec: function(env, args) { env.editor.navigateFileStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectup",
|
name: "selectup",
|
||||||
bindKey: bindKey("Shift-Up", "Shift-Up"),
|
bindKey: bindKey("Shift-Up", "Shift-Up"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectUp(); }
|
exec: function(env, args) { env.editor.getSelection().selectUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "golineup",
|
name: "golineup",
|
||||||
bindKey: bindKey("Up", "Up|Ctrl-P"),
|
bindKey: bindKey("Up", "Up|Ctrl-P"),
|
||||||
exec: function(env, args) { env.editor.navigateUp(args.times); }
|
exec: function(env, args) { env.editor.navigateUp(args.times); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "copylinesdown",
|
name: "copylinesdown",
|
||||||
bindKey: bindKey("Ctrl-Alt-Down", "Command-Option-Down"),
|
bindKey: bindKey("Ctrl-Alt-Down", "Command-Option-Down"),
|
||||||
exec: function(env, args) { env.editor.copyLinesDown(); }
|
exec: function(env, args) { env.editor.copyLinesDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "movelinesdown",
|
name: "movelinesdown",
|
||||||
bindKey: bindKey("Alt-Down", "Option-Down"),
|
bindKey: bindKey("Alt-Down", "Option-Down"),
|
||||||
exec: function(env, args) { env.editor.moveLinesDown(); }
|
exec: function(env, args) { env.editor.moveLinesDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selecttoend",
|
name: "selecttoend",
|
||||||
bindKey: bindKey("Ctrl-Shift-End|Alt-Shift-Down", "Command-Shift-Down"),
|
bindKey: bindKey("Ctrl-Shift-End|Alt-Shift-Down", "Command-Shift-Down"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectFileEnd(); }
|
exec: function(env, args) { env.editor.getSelection().selectFileEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotoend",
|
name: "gotoend",
|
||||||
bindKey: bindKey("Ctrl-End|Ctrl-Down", "Command-End|Command-Down"),
|
bindKey: bindKey("Ctrl-End|Ctrl-Down", "Command-End|Command-Down"),
|
||||||
exec: function(env, args) { env.editor.navigateFileEnd(); }
|
exec: function(env, args) { env.editor.navigateFileEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectdown",
|
name: "selectdown",
|
||||||
bindKey: bindKey("Shift-Down", "Shift-Down"),
|
bindKey: bindKey("Shift-Down", "Shift-Down"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectDown(); }
|
exec: function(env, args) { env.editor.getSelection().selectDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "golinedown",
|
name: "golinedown",
|
||||||
bindKey: bindKey("Down", "Down|Ctrl-N"),
|
bindKey: bindKey("Down", "Down|Ctrl-N"),
|
||||||
exec: function(env, args) { env.editor.navigateDown(args.times); }
|
exec: function(env, args) { env.editor.navigateDown(args.times); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectwordleft",
|
name: "selectwordleft",
|
||||||
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
|
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectWordLeft(); }
|
exec: function(env, args) { env.editor.getSelection().selectWordLeft(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotowordleft",
|
name: "gotowordleft",
|
||||||
bindKey: bindKey("Ctrl-Left", "Option-Left"),
|
bindKey: bindKey("Ctrl-Left", "Option-Left"),
|
||||||
exec: function(env, args) { env.editor.navigateWordLeft(); }
|
exec: function(env, args) { env.editor.navigateWordLeft(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selecttolinestart",
|
name: "selecttolinestart",
|
||||||
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
|
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
|
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotolinestart",
|
name: "gotolinestart",
|
||||||
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
|
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
|
||||||
exec: function(env, args) { env.editor.navigateLineStart(); }
|
exec: function(env, args) { env.editor.navigateLineStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectleft",
|
name: "selectleft",
|
||||||
bindKey: bindKey("Shift-Left", "Shift-Left"),
|
bindKey: bindKey("Shift-Left", "Shift-Left"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectLeft(); }
|
exec: function(env, args) { env.editor.getSelection().selectLeft(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotoleft",
|
name: "gotoleft",
|
||||||
bindKey: bindKey("Left", "Left|Ctrl-B"),
|
bindKey: bindKey("Left", "Left|Ctrl-B"),
|
||||||
exec: function(env, args) { env.editor.navigateLeft(args.times); }
|
exec: function(env, args) { env.editor.navigateLeft(args.times); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectwordright",
|
name: "selectwordright",
|
||||||
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
|
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectWordRight(); }
|
exec: function(env, args) { env.editor.getSelection().selectWordRight(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotowordright",
|
name: "gotowordright",
|
||||||
bindKey: bindKey("Ctrl-Right", "Option-Right"),
|
bindKey: bindKey("Ctrl-Right", "Option-Right"),
|
||||||
exec: function(env, args) { env.editor.navigateWordRight(); }
|
exec: function(env, args) { env.editor.navigateWordRight(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selecttolineend",
|
name: "selecttolineend",
|
||||||
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
|
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
|
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotolineend",
|
name: "gotolineend",
|
||||||
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
|
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
|
||||||
exec: function(env, args) { env.editor.navigateLineEnd(); }
|
exec: function(env, args) { env.editor.navigateLineEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectright",
|
name: "selectright",
|
||||||
bindKey: bindKey("Shift-Right", "Shift-Right"),
|
bindKey: bindKey("Shift-Right", "Shift-Right"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectRight(); }
|
exec: function(env, args) { env.editor.getSelection().selectRight(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotoright",
|
name: "gotoright",
|
||||||
bindKey: bindKey("Right", "Right|Ctrl-F"),
|
bindKey: bindKey("Right", "Right|Ctrl-F"),
|
||||||
exec: function(env, args) { env.editor.navigateRight(args.times); }
|
exec: function(env, args) { env.editor.navigateRight(args.times); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectpagedown",
|
name: "selectpagedown",
|
||||||
bindKey: bindKey("Shift-PageDown", "Shift-PageDown"),
|
bindKey: bindKey("Shift-PageDown", "Shift-PageDown"),
|
||||||
exec: function(env, args) { env.editor.selectPageDown(); }
|
exec: function(env, args) { env.editor.selectPageDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "pagedown",
|
name: "pagedown",
|
||||||
bindKey: bindKey(null, "PageDown"),
|
bindKey: bindKey(null, "PageDown"),
|
||||||
exec: function(env, args) { env.editor.scrollPageDown(); }
|
exec: function(env, args) { env.editor.scrollPageDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotopagedown",
|
name: "gotopagedown",
|
||||||
bindKey: bindKey("PageDown", "Option-PageDown|Ctrl-V"),
|
bindKey: bindKey("PageDown", "Option-PageDown|Ctrl-V"),
|
||||||
exec: function(env, args) { env.editor.gotoPageDown(); }
|
exec: function(env, args) { env.editor.gotoPageDown(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectpageup",
|
name: "selectpageup",
|
||||||
bindKey: bindKey("Shift-PageUp", "Shift-PageUp"),
|
bindKey: bindKey("Shift-PageUp", "Shift-PageUp"),
|
||||||
exec: function(env, args) { env.editor.selectPageUp(); }
|
exec: function(env, args) { env.editor.selectPageUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "pageup",
|
name: "pageup",
|
||||||
bindKey: bindKey(null, "PageUp"),
|
bindKey: bindKey(null, "PageUp"),
|
||||||
exec: function(env, args) { env.editor.scrollPageUp(); }
|
exec: function(env, args) { env.editor.scrollPageUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "gotopageup",
|
name: "gotopageup",
|
||||||
bindKey: bindKey("PageUp", "Option-PageUp"),
|
bindKey: bindKey("PageUp", "Option-PageUp"),
|
||||||
exec: function(env, args) { env.editor.gotoPageUp(); }
|
exec: function(env, args) { env.editor.gotoPageUp(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectlinestart",
|
name: "selectlinestart",
|
||||||
bindKey: bindKey("Shift-Home", "Shift-Home"),
|
bindKey: bindKey("Shift-Home", "Shift-Home"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
|
exec: function(env, args) { env.editor.getSelection().selectLineStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "selectlineend",
|
name: "selectlineend",
|
||||||
bindKey: bindKey("Shift-End", "Shift-End"),
|
bindKey: bindKey("Shift-End", "Shift-End"),
|
||||||
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
|
exec: function(env, args) { env.editor.getSelection().selectLineEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "del",
|
name: "del",
|
||||||
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
|
bindKey: bindKey("Delete", "Delete|Ctrl-D"),
|
||||||
exec: function(env, args) { env.editor.removeRight(); }
|
exec: function(env, args) { env.editor.removeRight(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "backspace",
|
name: "backspace",
|
||||||
bindKey: bindKey(
|
bindKey: bindKey(
|
||||||
"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
|
"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
|
||||||
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
|
"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
|
||||||
),
|
),
|
||||||
exec: function(env, args) { env.editor.removeLeft(); }
|
exec: function(env, args) { env.editor.removeLeft(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "removetolinestart",
|
name: "removetolinestart",
|
||||||
bindKey: bindKey(null, "Option-Backspace"),
|
bindKey: bindKey(null, "Option-Backspace"),
|
||||||
exec: function(env, args) { env.editor.removeToLineStart(); }
|
exec: function(env, args) { env.editor.removeToLineStart(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "removetolineend",
|
name: "removetolineend",
|
||||||
bindKey: bindKey(null, "Ctrl-K"),
|
bindKey: bindKey(null, "Ctrl-K"),
|
||||||
exec: function(env, args) { env.editor.removeToLineEnd(); }
|
exec: function(env, args) { env.editor.removeToLineEnd(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "removewordleft",
|
name: "removewordleft",
|
||||||
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
|
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
|
||||||
exec: function(env, args) { env.editor.removeWordLeft(); }
|
exec: function(env, args) { env.editor.removeWordLeft(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "removewordright",
|
name: "removewordright",
|
||||||
bindKey: bindKey(null, "Alt-Delete"),
|
bindKey: bindKey(null, "Alt-Delete"),
|
||||||
exec: function(env, args) { env.editor.removeWordRight(); }
|
exec: function(env, args) { env.editor.removeWordRight(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "outdent",
|
name: "outdent",
|
||||||
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
|
bindKey: bindKey("Shift-Tab", "Shift-Tab"),
|
||||||
exec: function(env, args) { env.editor.blockOutdent(); }
|
exec: function(env, args) { env.editor.blockOutdent(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "indent",
|
name: "indent",
|
||||||
bindKey: bindKey("Tab", "Tab"),
|
bindKey: bindKey("Tab", "Tab"),
|
||||||
exec: function(env, args) { env.editor.indent(); }
|
exec: function(env, args) { env.editor.indent(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "inserttext",
|
name: "inserttext",
|
||||||
exec: function(env, args) {
|
exec: function(env, args) {
|
||||||
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
|
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
|
||||||
}
|
}
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "centerselection",
|
name: "centerselection",
|
||||||
bindKey: bindKey(null, "Ctrl-L"),
|
bindKey: bindKey(null, "Ctrl-L"),
|
||||||
exec: function(env, args) { env.editor.centerSelection(); }
|
exec: function(env, args) { env.editor.centerSelection(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "splitline",
|
name: "splitline",
|
||||||
bindKey: bindKey(null, "Ctrl-O"),
|
bindKey: bindKey(null, "Ctrl-O"),
|
||||||
exec: function(env, args) { env.editor.splitLine(); }
|
exec: function(env, args) { env.editor.splitLine(); }
|
||||||
});
|
}, {
|
||||||
commands.addCommand({
|
|
||||||
name: "transposeletters",
|
name: "transposeletters",
|
||||||
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
|
bindKey: bindKey("Ctrl-T", "Ctrl-T"),
|
||||||
exec: function(env, args) { env.editor.transposeLetters(); }
|
exec: function(env, args) { env.editor.transposeLetters(); }
|
||||||
});
|
}];
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -54,8 +54,10 @@ var EditSession = require("ace/edit_session").EditSession;
|
||||||
var Search = require("ace/search").Search;
|
var Search = require("ace/search").Search;
|
||||||
var Range = require("ace/range").Range;
|
var Range = require("ace/range").Range;
|
||||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||||
|
var CommandManager = require("ace/commands/command_manager").CommandManager;
|
||||||
|
var defaultCommands = require("ace/commands/default_commands").commands;
|
||||||
|
|
||||||
var Editor =function(renderer, session) {
|
var Editor = function(renderer, session) {
|
||||||
var container = renderer.getContainerElement();
|
var container = renderer.getContainerElement();
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
@ -75,6 +77,7 @@ var Editor =function(renderer, session) {
|
||||||
wrap: true
|
wrap: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.commands = new CommandManager(defaultCommands);
|
||||||
this.setSession(session || new EditSession(""));
|
this.setSession(session || new EditSession(""));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ define(function(require, exports, module) {
|
||||||
var useragent = require("pilot/useragent");
|
var useragent = require("pilot/useragent");
|
||||||
var keyUtil = require("pilot/keys");
|
var keyUtil = require("pilot/keys");
|
||||||
var event = require("pilot/event");
|
var event = require("pilot/event");
|
||||||
var commands = require("ace/commands/command_manager");
|
|
||||||
require("ace/commands/default_commands");
|
require("ace/commands/default_commands");
|
||||||
|
|
||||||
var KeyBinding = function(editor) {
|
var KeyBinding = function(editor) {
|
||||||
|
|
@ -63,14 +62,16 @@ var KeyBinding = function(editor) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$callKeyboardHandler = function (e, hashId, keyOrText, keyCode) {
|
this.$callKeyboardHandler = function (e, hashId, keyOrText, keyCode) {
|
||||||
var env = {editor: this.$editor},
|
var env = {editor: this.$editor};
|
||||||
toExecute;
|
var toExecute;
|
||||||
|
var commands = this.$editor.commands;
|
||||||
|
|
||||||
if (this.$keyboardHandler) {
|
if (this.$keyboardHandler) {
|
||||||
toExecute =
|
toExecute =
|
||||||
this.$keyboardHandler.handleKeyboard(this.$data, hashId, keyOrText, keyCode, e);
|
this.$keyboardHandler.handleKeyboard(this.$data, hashId, keyOrText, keyCode, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If there is nothing to execute yet, then use the default keymapping.
|
// If there is nothing to execute yet, then use the default keymapping.
|
||||||
if (!toExecute || !toExecute.command) {
|
if (!toExecute || !toExecute.command) {
|
||||||
if (hashId != 0 || keyCode != 0) {
|
if (hashId != 0 || keyCode != 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue