From 2c634d9b2324c760007d59d5cafd97a364125991 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 20 Feb 2016 09:44:57 +0000 Subject: Add `count` command option. Examples: map j scrollDown count=10 map q removeTab count=999 --- background_scripts/commands.coffee | 9 +++++++-- background_scripts/main.coffee | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 47eb7e8e..8d73c913 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -56,7 +56,7 @@ Commands = if command? and @availableCommands[command] key = @normalizeKey key logMessage? "Mapping #{key} to #{command}" - @mapKeyToCommand { key, command, options: @parseCommandOptions optionList } + @mapKeyToCommand { key, command, options: @parseCommandOptions command, optionList } when "unmap" if tokens.length == 2 @@ -77,7 +77,7 @@ Commands = # Command options follow command mappings, and are of one of two forms: # key=value - a value # key - a flag - parseCommandOptions: (optionList) -> + parseCommandOptions: (command, optionList) -> options = {} for option in optionList parse = option.split "=" @@ -88,6 +88,11 @@ Commands = options[parse[0]] = parse[1] else console.log "Vimium configuration error: invalid option: #{option}." + + # 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: -> diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 5601b20d..283fa454 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -573,6 +573,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" -- cgit v1.2.3