From a16380eaea87583e37d94ca518bb4f96d7613fb9 Mon Sep 17 00:00:00 2001 From: Robert Krahn Date: Sun, 26 May 2013 21:07:22 -0700 Subject: [PATCH] emacs: fix bindKey register all partial key combos as null commands to be able to activate key combos with arbitrary length Example: if keyPart is "C-c C-l t" then "C-c C-l t" will get command assigned and "C-c" and "C-c C-l" will get a null command assigned --- lib/ace/keyboard/emacs.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/ace/keyboard/emacs.js b/lib/ace/keyboard/emacs.js index 2c2cf34d..8d6b8985 100644 --- a/lib/ace/keyboard/emacs.js +++ b/lib/ace/keyboard/emacs.js @@ -202,12 +202,21 @@ exports.handler.bindKey = function(key, command) { key.split("|").forEach(function(keyPart) { keyPart = keyPart.toLowerCase(); ckb[keyPart] = command; - keyPart = keyPart.split(" ")[0]; - if (!ckb[keyPart]) - ckb[keyPart] = "null"; + // register all partial key combos as null commands + // to be able to activate key combos with arbitrary length + // Example: if keyPart is "C-c C-l t" then "C-c C-l t" will + // get command assigned and "C-c" and "C-c C-l" will get + // a null command assigned in this.commmandKeyBinding. For + // the lookup logic see handleKeyboard() + var keyParts = keyPart.split(" ").slice(0,-1); + keyParts.reduce(function(keyMapKeys, keyPart, i) { + var prefix = keyMapKeys[i-1] ? keyMapKeys[i-1] + ' ' : ''; + return keyMapKeys.concat([prefix + keyPart]); + }, []).forEach(function(keyPart) { + if (!ckb[keyPart]) ckb[keyPart] = "null"; + }); }, this); -}; - +} exports.handler.handleKeyboard = function(data, hashId, key, keyCode) { var editor = data.editor;