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
This commit is contained in:
Robert Krahn 2013-05-26 21:07:22 -07:00
commit a16380eaea

View file

@ -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;