diff --git a/lib/ace/keyboard/emacs.js b/lib/ace/keyboard/emacs.js index a09119ce..aee6ff4b 100644 --- a/lib/ace/keyboard/emacs.js +++ b/lib/ace/keyboard/emacs.js @@ -164,6 +164,7 @@ exports.handler.bindKey = function(key, command) { exports.handler.handleKeyboard = function(data, hashId, key, keyCode) { + // insertstring data.count times if (hashId == -1) { exports.setMarkMode(null); if (data.count) { @@ -177,6 +178,8 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) { return; var modifier = eMods[hashId]; + + // CTRL + number / universalArgument for setting data.count if (modifier == "c-" || data.universalArgument) { var count = parseInt(key[key.length - 1]); if (count) { @@ -186,42 +189,47 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) { } data.universalArgument = false; - if (modifier) - key = modifier + key; + // this.commandKeyBinding maps key specs like "c-p" (for CTRL + P) to + // command objects, for lookup key needs to include the modifier + if (modifier) key = modifier + key; - if (data.keyChain) - key = data.keyChain += " " + key; + // Key combos like CTRL+X H build up the data.keyChain + if (data.keyChain) key = data.keyChain += " " + key; + // Key combo prefixes get stored as "null" (String!) in this + // this.commmandKeyBinding. When encountered no command is invoked but we + // buld up data.keyChain var command = this.commmandKeyBinding[key]; data.keyChain = command == "null" ? key : ""; - if (!command) - return; + // there really is no command + if (!command) return; - if (command == "null") - return {command: "null"}; + // we pass b/c of key combo or universalArgument + if (command === "null") return {command: "null"}; - if (command == "universalArgument") { + if (command === "universalArgument") { data.universalArgument = true; return {command: "null"}; } - if (typeof command != "string") { - var args = command.args; - command = command.command; - if (command == "goorselect") { - command = args[0]; - if (exports.markMode()) { - command = args[1]; - } + // lookup command + // TODO extract special handling of markmode + // TODO special case command.command is really unnecessary, remove + var args; + if (typeof command !== "string") { + args = command.args; + if (command.command) command = command.command; + if (command === "goorselect") { + command = exports.markMode() ? args[1] : args[0]; args = null; } } - if (typeof command == "string") { - if (command == "insertstring" || - command == "splitline" || - command == "togglecomment") { + if (typeof command === "string") { + if (command === "insertstring" || + command === "splitline" || + command === "togglecomment") { exports.setMarkMode(null); } command = this.commands[command] || data.editor.commands.commands[command];