From 5783bae0587406e6482c08490da4360e131a3263 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 15 Feb 2014 13:49:42 +0400 Subject: [PATCH] add event.getModifierString to convert hash into readable string --- lib/ace/keyboard/vim.js | 4 ++-- lib/ace/lib/event.js | 4 ++++ lib/ace/lib/keys.js | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ace/keyboard/vim.js b/lib/ace/keyboard/vim.js index fdd88117..3ae4842f 100644 --- a/lib/ace/keyboard/vim.js +++ b/lib/ace/keyboard/vim.js @@ -145,8 +145,8 @@ exports.handler = { if (hashId == -1 || hashId == 1 || hashId === 0 && key.length > 1) { if (cmds.inputBuffer.idle && startCommands[key]) return startCommands[key]; - cmds.inputBuffer.push(editor, key); - return {command: "null", passEvent: false}; + var isHandled = cmds.inputBuffer.push(editor, key); + return {command: "null", passEvent: !isHandled}; } // if no modifier || shift: wait for input. else if (key.length == 1 && (hashId === 0 || hashId == 4)) { return {command: "null", passEvent: true}; diff --git a/lib/ace/lib/event.js b/lib/ace/lib/event.js index 8966f001..9ad0c3ac 100644 --- a/lib/ace/lib/event.js +++ b/lib/ace/lib/event.js @@ -217,6 +217,10 @@ var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0); }; +exports.getModifierString = function(e) { + return keys.KEY_MODS[getModifierHash(e)]; +}; + function normalizeCommandKeys(callback, e, keyCode) { var hashId = getModifierHash(e); diff --git a/lib/ace/lib/keys.js b/lib/ace/lib/keys.js index 916d9f00..78cede51 100644 --- a/lib/ace/lib/keys.js +++ b/lib/ace/lib/keys.js @@ -133,6 +133,15 @@ var Keys = (function() { // workaround for firefox bug ret[173] = '-'; + + (function() { + var mods = ["cmd", "ctrl", "alt", "shift"]; + for (var i = Math.pow(2, mods.length); i--;) { + ret.KEY_MODS[i] = mods.filter(function(x) { + return i & ret.KEY_MODS[x]; + }).join("-") + "-"; + } + })(); return ret; })(); @@ -140,6 +149,6 @@ oop.mixin(exports, Keys); exports.keyCodeToString = function(keyCode) { return (Keys[keyCode] || String.fromCharCode(keyCode)).toLowerCase(); -} +}; });