diff options
| author | Stephen Blott | 2016-02-20 09:16:07 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-02-20 09:16:07 +0000 |
| commit | 61ce82be4acae20562bb2ccb93ff64772ba553c1 (patch) | |
| tree | 51c1c5f29b1b0349ed0587fdaf83dda3d01b60df /background_scripts | |
| parent | e6200864be1bad085ae80e0a0c51d077ca1289a5 (diff) | |
| download | vimium-61ce82be4acae20562bb2ccb93ff64772ba553c1.tar.bz2 | |
Refactor command-option parsing.
When we introduced command options (for mapping keys to custom-search
engines), the parsing was done in the Vomnibar code.
This moves the parsing to `commands.coffee`, which is where it should
always have been.
This is a preliminary step with a view to adding a new `count` command
option.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/commands.coffee | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 80ca0f96..47eb7e8e 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -52,11 +52,11 @@ Commands = tokens = line.replace(/\s+$/, "").split /\s+/ switch tokens[0] when "map" - [ _, key, command, options... ] = tokens + [ _, key, command, optionList... ] = tokens if command? and @availableCommands[command] key = @normalizeKey key logMessage? "Mapping #{key} to #{command}" - @mapKeyToCommand { key, command, options } + @mapKeyToCommand { key, command, options: @parseCommandOptions optionList } when "unmap" if tokens.length == 2 @@ -74,6 +74,22 @@ Commands = Settings.set "passNextKeyKeys", (key for own key of @keyToCommandRegistry when @keyToCommandRegistry[key].command == "passNextKey" and 1 < key.length) + # Command options follow command mappings, and are of one of two forms: + # key=value - a value + # key - a flag + parseCommandOptions: (optionList) -> + options = {} + for option in optionList + parse = option.split "=" + switch parse.length + when 1 + options[parse[0]] = true + when 2 + options[parse[0]] = parse[1] + else + console.log "Vimium configuration error: invalid option: #{option}." + options + clearKeyMappingsAndSetDefaults: -> @keyToCommandRegistry = {} @mapKeyToCommand { key, command } for own key, command of defaultKeyMappings |
