diff options
| -rw-r--r-- | background_scripts/commands.coffee | 8 | ||||
| -rw-r--r-- | content_scripts/mode_key_handler.coffee | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 7a4526c2..17c05f90 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -9,6 +9,7 @@ Commands = @clearKeyMappingsAndSetDefaults() @parseCustomKeyMappings customKeyMappings @generateKeyStateMapping() + chrome.storage.local.set keyTranslationRegistry: @keyTranslationRegistry availableCommands: {} keyToCommandRegistry: {} @@ -84,6 +85,12 @@ Commands = when "unmapAll" @keyToCommandRegistry = {} + when "translate" + if tokens.length == 3 + fromChar = @parseKeySequence tokens[1] + toChar = @parseKeySequence tokens[2] + @keyTranslationRegistry[fromChar[0]] = toChar[0] if fromChar.length == toChar.length == 1 + # Push the key mapping for passNextKey into Settings so that it's available in the front end for insert # mode. We exclude single-key mappings (that is, printable keys) because when users press printable keys # in insert mode they expect the character to be input, not to be droppped into some special Vimium @@ -109,6 +116,7 @@ Commands = clearKeyMappingsAndSetDefaults: -> @keyToCommandRegistry = {} + @keyTranslationRegistry = {} for own key, command of defaultKeyMappings keySequence = @parseKeySequence key key = keySequence.join "" diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index 8c0ae4b8..7904d801 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -33,8 +33,16 @@ class KeyHandlerMode extends Mode # We cannot track keyup events if we lose the focus. blur: (event) => @alwaysContinueBubbling => @keydownEvents = {} if event.target == window + @keyTranslationRegistry = {} + chrome.storage.local.get "keyTranslationRegistry", (obj) => + @keyTranslationRegistry = obj.keyTranslationRegistry + chrome.storage.onChanged.addListener (changes, area) => + if area == "local" and changes.keyTranslationRegistry?.newValue? + @keyTranslationRegistry = changes.keyTranslationRegistry.newValue + onKeydown: (event) -> keyChar = KeyboardUtils.getKeyCharString event + keyChar = @keyTranslationRegistry[keyChar] ? keyChar isEscape = KeyboardUtils.isEscape event if isEscape and (@countPrefix != 0 or @keyState.length != 1) @keydownEvents[event.keyCode] = true @@ -61,6 +69,7 @@ class KeyHandlerMode extends Mode onKeypress: (event) -> keyChar = KeyboardUtils.getKeyCharString event + keyChar = @keyTranslationRegistry[keyChar] ? keyChar if @isMappedKey keyChar @handleKeyChar keyChar else if @isCountKey keyChar |
