diff options
| author | Stephen Blott | 2016-02-27 14:20:12 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-05 05:37:40 +0000 | 
| commit | 34b1fb0f4e2ce1696c17e703d0bc43463355d6ba (patch) | |
| tree | 0bf5797129ae1f212154b56aff86be0830073a29 /background_scripts/commands.coffee | |
| parent | 7c5fb2c312b9140c2dd091f792535ae8f592ecdb (diff) | |
| download | vimium-34b1fb0f4e2ce1696c17e703d0bc43463355d6ba.tar.bz2 | |
Key bindings; initial partially-functioning version.
Diffstat (limited to 'background_scripts/commands.coffee')
| -rw-r--r-- | background_scripts/commands.coffee | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index ab9992b3..a1002929 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -94,6 +94,25 @@ Commands =      @keyToCommandRegistry = {}      @mapKeyToCommand { key, command } for own key, command of defaultKeyMappings +  # Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (left arrow) or <f12> +  # This regular expression captures two groups: the first is a named key, the second is the remainder of the +  # string. +  namedKeyRegex: /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/ + +  generateKeyStateStructure: -> +    keyMapping = {} +    for own keys, registryEntry of @keyToCommandRegistry +      currentMapping = keyMapping +      while 0 < keys.length +        [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys.slice(1)] +        if 0 < rest.length +          currentMapping[key] ?= {} +          currentMapping = currentMapping[key] +        else +          currentMapping[key] = registryEntry +        keys = rest +    chrome.storage.local.set normalModeKeyStateMapping: keyMapping +    # An ordered listing of all available commands, grouped by type. This is the order they will    # be shown in the help page.    commandGroups: @@ -375,6 +394,7 @@ Commands.init()  Settings.postUpdateHooks["keyMappings"] = (value) ->    Commands.clearKeyMappingsAndSetDefaults()    Commands.parseCustomKeyMappings value +  Commands.generateKeyStateStructure()    refreshCompletionKeysAfterMappingSave()  root = exports ? window | 
