diff options
| author | Stephen Blott | 2016-02-20 11:59:05 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-02-20 11:59:05 +0000 |
| commit | c818edb5e0e1a1edbcccfb2b978bf2e535de9fb4 (patch) | |
| tree | a8c3f4c3670b21b3f190fc3849bea919fb60ce11 /background_scripts | |
| parent | ac2018212ad438b70263d6a183e388d6a7e595d8 (diff) | |
| parent | 70b8645d61a56ea760864d222791494aa6031f92 (diff) | |
| download | vimium-c818edb5e0e1a1edbcccfb2b978bf2e535de9fb4.tar.bz2 | |
Merge pull request #2001 from smblott-github/add-count-command-option
Add count command option
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/commands.coffee | 19 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 2 |
2 files changed, 19 insertions, 2 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 80ca0f96..d251c7ed 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 command, optionList } when "unmap" if tokens.length == 2 @@ -74,6 +74,21 @@ 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: (command, optionList) -> + options = {} + for option in optionList + parse = option.split "=", 2 + options[parse[0]] = if parse.length == 1 then true else parse[1] + + # We parse any `count` option immediately (to avoid having to parse it repeatedly later). + unless @availableCommands[command].noRepeat + options.count = try Math.max 1, parseInt options.count + + options + clearKeyMappingsAndSetDefaults: -> @keyToCommandRegistry = {} @mapKeyToCommand { key, command } for own key, command of defaultKeyMappings diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index c824db88..0e043159 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -534,6 +534,8 @@ checkKeyQueue = (keysToCheck, tabId, frameId) -> """ if runCommand + # Account for any command-option "count". + count *= registryEntry.options.count ? 1 if not registryEntry.isBackgroundCommand chrome.tabs.sendMessage tabId, name: "executePageCommand" |
