From 6596e30392a1ca053223825eda5cde060394a4aa Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 9 Oct 2016 15:20:15 +0100 Subject: Add translate command for key mappings. Under *Custom key mappings* (on the options page), this implements: translate x y Whenever the users types `x` in normal mode or in visual mode, the `x` is replaced by `y`. For example: map รง l (which apparently would be helpful on Brazilian keyboards). Issues: - Do we want yet another hack like this? This would be documented only on the wiki. - If we allowed `translate ` (and extended `isEscape()` to use the translation), then we'd get the `exitMode` command for free (#2253). - Alternatively, instead of adding a new "command" called `translate`, we could overload the existing `map` command. Since these are single-key mappings, there's no ambiguity. (Although, I guess there's a risk some user has junk in their key mappings and would be taken by surprise). Inspired by isssue posted by @vhoyer (#2305). Fixes #2305. --- background_scripts/commands.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'background_scripts') 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 "" -- cgit v1.2.3 From c5e26d75cb8525ba34f6f54f1a1c041df66075e3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 10 Oct 2016 13:27:32 +0100 Subject: Rename 'translate' to 'mapkey'. --- background_scripts/commands.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 17c05f90..d12b704d 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -9,7 +9,7 @@ Commands = @clearKeyMappingsAndSetDefaults() @parseCustomKeyMappings customKeyMappings @generateKeyStateMapping() - chrome.storage.local.set keyTranslationRegistry: @keyTranslationRegistry + chrome.storage.local.set mapKeyRegistry: @mapKeyRegistry availableCommands: {} keyToCommandRegistry: {} @@ -85,11 +85,11 @@ Commands = when "unmapAll" @keyToCommandRegistry = {} - when "translate" + when "mapkey" if tokens.length == 3 fromChar = @parseKeySequence tokens[1] toChar = @parseKeySequence tokens[2] - @keyTranslationRegistry[fromChar[0]] = toChar[0] if fromChar.length == toChar.length == 1 + @mapKeyRegistry[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 @@ -116,7 +116,7 @@ Commands = clearKeyMappingsAndSetDefaults: -> @keyToCommandRegistry = {} - @keyTranslationRegistry = {} + @mapKeyRegistry = {} for own key, command of defaultKeyMappings keySequence = @parseKeySequence key key = keySequence.join "" -- cgit v1.2.3