aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/commands.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-02-28 15:35:10 +0000
committerStephen Blott2016-03-05 05:39:33 +0000
commitb0d2f3bfbc36232c235f913131c78a5bb76b59c3 (patch)
tree104c3cc8069a6523fdec5e59b551a59b66549354 /background_scripts/commands.coffee
parentb63683a1026e12bfd7bff6b8745d18e3b858bf92 (diff)
downloadvimium-b0d2f3bfbc36232c235f913131c78a5bb76b59c3.tar.bz2
Key bindings; and yet more minor tweaks.
Diffstat (limited to 'background_scripts/commands.coffee')
-rw-r--r--background_scripts/commands.coffee27
1 files changed, 13 insertions, 14 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 50e5d624..46869451 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -1,13 +1,13 @@
Commands =
- init: (customKeyMappings) ->
+ init: () ->
for own command, description of commandDescriptions
@addCommand(command, description[0], description[1])
- @loadKeyMappings customKeyMappings
+ @loadKeyMappings Settings.get "keyMappings"
Settings.postUpdateHooks["keyMappings"] = @loadKeyMappings.bind this
- loadKeyMappings: (value) ->
+ loadKeyMappings: (customKeyMappings) ->
@clearKeyMappingsAndSetDefaults()
- @parseCustomKeyMappings value
+ @parseCustomKeyMappings customKeyMappings
@generateKeyStateMapping()
availableCommands: {}
@@ -107,19 +107,18 @@ Commands =
namedKeyRegex: /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/
generateKeyStateMapping: ->
- keyMapping = {}
+ keyStateMapping = {}
for own keys, registryEntry of @keyToCommandRegistry
- currentMapping = keyMapping
+ currentMapping = keyStateMapping
while 0 < keys.length
- [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]]
- if 0 < rest.length
- # Do not overwrite existing command bindings, they take priority.
- break if (currentMapping[key] ?= {}).command
- currentMapping = currentMapping[key]
+ [key, keys] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]]
+ if currentMapping[key]?.command
+ break # Do not overwrite existing command bindings, they take priority.
+ else if 0 < keys.length
+ currentMapping = (currentMapping[key] ?= {})
else
currentMapping[key] = registryEntry
- keys = rest
- chrome.storage.local.set normalModeKeyStateMapping: keyMapping
+ chrome.storage.local.set normalModeKeyStateMapping: keyStateMapping
# An ordered listing of all available commands, grouped by type. This is the order they will
# be shown in the help page.
@@ -397,7 +396,7 @@ commandDescriptions =
"Marks.activateCreateMode": ["Create a new mark", { noRepeat: true }]
"Marks.activateGotoMode": ["Go to a mark", { noRepeat: true }]
-Commands.init Settings.get "keyMappings"
+Commands.init()
root = exports ? window
root.Commands = Commands