diff options
| author | Stephen Blott | 2016-10-09 16:31:23 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-10-09 16:31:23 +0100 |
| commit | 9c1012ad3a731b015b8a70b58828fbcd0acb7db0 (patch) | |
| tree | edb48cc06710408e082f59619779080051640b46 /lib | |
| parent | 6596e30392a1ca053223825eda5cde060394a4aa (diff) | |
| download | vimium-9c1012ad3a731b015b8a70b58828fbcd0acb7db0.tar.bz2 | |
Extend key translation to include Escape.
Here, these map to escape:
translate x <c-[>
translate <c-c> <c-[>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/keyboard_utils.coffee | 35 | ||||
| -rw-r--r-- | lib/utils.coffee | 7 |
2 files changed, 30 insertions, 12 deletions
diff --git a/lib/keyboard_utils.coffee b/lib/keyboard_utils.coffee index f0e791d4..7f48d69e 100644 --- a/lib/keyboard_utils.coffee +++ b/lib/keyboard_utils.coffee @@ -79,10 +79,18 @@ KeyboardUtils = isPrimaryModifierKey: (event) -> if (@platform == "Mac") then event.metaKey else event.ctrlKey - isEscape: (event) -> - # c-[ is mapped to ESC in Vim by default. - (event.keyCode == @keyCodes.ESC) || - (event.ctrlKey && @getKeyChar(event) == '[' and not event.metaKey and not event.altKey) + isEscape: do -> + keyTranslationRegistry = {} + # NOTE: "?" here for the tests. + Utils?.monitorChromeStorage "keyTranslationRegistry", (value) => keyTranslationRegistry = value + + (event) -> + event.keyCode == @keyCodes.ESC || do => + keyChar = @getKeyChar event + keyChar.length == 1 and do => + keyChar = @getModifiedKeyChar keyChar, event + keyChar = keyTranslationRegistry[keyChar] ? keyChar + keyChar == "<c-[>" # TODO. This is probably a poor way of detecting printable characters. However, it shouldn't incorrectly # identify any of chrome's own keyboard shortcuts as printable. @@ -108,16 +116,19 @@ KeyboardUtils = # Handle special keys and normal input keys with modifiers being pressed. keyChar = @getKeyChar event if 1 < keyChar.length or (keyChar.length == 1 and (event.metaKey or event.ctrlKey or event.altKey)) - modifiers = [] + @getModifiedKeyChar keyChar, event + + getModifiedKeyChar: (keyChar, event) -> + modifiers = [] - keyChar = keyChar.toUpperCase() if event.shiftKey - # These must be in alphabetical order (to match the sorted modifier order in Commands.normalizeKey). - modifiers.push "a" if event.altKey - modifiers.push "c" if event.ctrlKey - modifiers.push "m" if event.metaKey + keyChar = keyChar.toUpperCase() if event.shiftKey + # These must be in alphabetical order (to match the sorted modifier order in Commands.normalizeKey). + modifiers.push "a" if event.altKey + modifiers.push "c" if event.ctrlKey + modifiers.push "m" if event.metaKey - keyChar = [modifiers..., keyChar].join "-" - if 1 < keyChar.length then "<#{keyChar}>" else keyChar + keyChar = [modifiers..., keyChar].join "-" + if 1 < keyChar.length then "<#{keyChar}>" else keyChar KeyboardUtils.init() diff --git a/lib/utils.coffee b/lib/utils.coffee index c06d8ac5..5a028186 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -209,6 +209,13 @@ Utils = makeIdempotent: (func) -> (args...) -> ([previousFunc, func] = [func, null])[0]? args... + monitorChromeStorage: (key, setter) -> + # NOTE: "?" here for the tests. + chrome?.storage.local.get key, (obj) => + setter obj[key] if obj[key]? + chrome.storage.onChanged.addListener (changes, area) => + setter changes[key].newValue if changes[key]?.newValue? + # Utility for parsing and using the custom search-engine configuration. We re-use the previous parse if the # search-engine configuration is unchanged. SearchEngines = |
