diff options
| -rw-r--r-- | background_scripts/commands.coffee | 4 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 10 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 3 | ||||
| -rw-r--r-- | content_scripts/mode_key_handler.coffee | 25 | 
4 files changed, 11 insertions, 31 deletions
| diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index e32707ce..50e5d624 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -8,7 +8,7 @@ Commands =    loadKeyMappings: (value) ->      @clearKeyMappingsAndSetDefaults()      @parseCustomKeyMappings value -    @generateKeyStateStructure() +    @generateKeyStateMapping()    availableCommands: {}    keyToCommandRegistry: {} @@ -106,7 +106,7 @@ Commands =    # string.    namedKeyRegex: /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/ -  generateKeyStateStructure: -> +  generateKeyStateMapping: ->      keyMapping = {}      for own keys, registryEntry of @keyToCommandRegistry        currentMapping = keyMapping diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f5bf90a6..d1ca501d 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -369,16 +369,10 @@ chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) ->  # End action functions -# Open Vomnibar in tab's main frame. -openVomnibar = (tabId, frameId, registryEntry) -> -  chrome.tabs.sendMessage tabId, -    name: "openVomnibar" -    sourceFrameId: frameId -    registryEntry: registryEntry -  runBackgroundCommand = ({frameId, registryEntry, count}, sender) ->    if registryEntry.command.split(".")[0] == "Vomnibar" -    openVomnibar sender.tab.id, frameId, registryEntry +    chrome.tabs.sendMessage sender.tab.id, +      name: "openVomnibar", sourceFrameId: frameId, registryEntry: registryEntry    else if registryEntry.passCountToFunction      BackgroundCommands[registryEntry.command] count, frameId    else if registryEntry.noRepeat diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index efbc9cf4..8a84457e 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -119,8 +119,7 @@ class Mode          @deactivateSingleton @options.singleton          singletons[key] = this -    # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys, -    # and calls @registerStateChange() (if defined) whenever the state changes. +    # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys.      if @options.trackState        @enabled = false        @passKeys = "" diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index c9cab244..e38a7051 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -21,16 +21,14 @@ class KeyHandlerMode extends Mode    onKeydown: (event) ->      keyChar = KeyboardUtils.getKeyCharString event      if KeyboardUtils.isEscape event -      if @isInResetState() +      if @countPrefix == 0 and @keyState.length == 1          @continueBubbling        else          @reset()          DomUtils.suppressKeyupAfterEscape handlerStack          false # Suppress event. -      else if keyChar and @mappingForKeyChar keyChar        @handleKeyChar event, keyChar -      else        # We did not handle the event, but we might handle a subsequent keypress.  If we will be handling that        # event, then we suppress propagation of this keydown to prevent triggering page events. @@ -84,26 +82,15 @@ class KeyHandlerMode extends Mode      newMappings = (mapping[keyChar] for mapping in @keyState when keyChar of mapping)      @keyState = [newMappings..., @keyMapping] -  # Reset the state (as if no keys had been handled), but retaining the count - if one is provided. -  reset: (count = 0) -> -    bgLog "Clearing key queue, set count=#{count}." -    @countPrefix = count +  # Reset the state (as if no keys had been handled), but optionally retaining the count provided. +  reset: (@countPrefix = 0) -> +    bgLog "Clearing key queue, set count=#{@countPrefix}."      @keyState = [@keyMapping] -  # This tests whether we are in the reset state.  It is used to check whether we should be using escape to -  # reset the key state, or passing it to the page. -  isInResetState: -> -    @countPrefix == 0 and @keyState.length == 1 - -  # This tests whether keyChar should be treated as a count key.    isCountKey: (keyChar) -> -    return false unless keyChar.length == 1 -    if 0 < @countPrefix -      '0' <= keyChar <= '9' -    else -      '1' <= keyChar <= '9' +    keyChar.length == 1 and (if 0 < @countPrefix then '0' else '1') <= keyChar <= '9' -  # Test whether keyChar would be the very first character of a command mapping. +  # This tests whether keyChar would be the very first character of a command mapping.    isFirstKeyChar: (keyChar) ->      keyChar and @countPrefix == 0 and (@mappingForKeyChar(keyChar) == @keyMapping or @isCountKey keyChar) | 
