diff options
| -rw-r--r-- | background_scripts/commands.coffee | 5 | ||||
| -rw-r--r-- | content_scripts/mode_key_handler.coffee | 24 | 
2 files changed, 14 insertions, 15 deletions
| diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index a82a6dcb..2982b861 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -104,10 +104,9 @@ Commands =      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)] +        [key, rest] = if 0 == keys.search @namedKeyRegex then [RegExp.$1, RegExp.$2] else [keys[0], keys[1..]]          if 0 < rest.length -          currentMapping[key] ?= {} -          currentMapping = currentMapping[key] +          currentMapping = currentMapping[key] ?= {}          else            currentMapping[key] = registryEntry          keys = rest diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index 7f03dd64..9b044923 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -36,10 +36,7 @@ class KeyHandlerMode extends Mode          false # Suppress event.      else if keyChar and @mappingForKeyChar keyChar -        @advanceKeyState keyChar -        commands = @keyState.filter (entry) -> "string" == typeof entry -        @invokeCommand commands[0] if 0 < commands.length -        false # Suppress event. +      @handleKeyChar event, keyChar      else        # We did not handle the event, but we might handle the subsequent keypress event.  If we *will* be @@ -57,12 +54,9 @@ class KeyHandlerMode extends Mode    onKeypress: (event) ->      keyChar = KeyboardUtils.getKeyCharString event      if keyChar and @mappingForKeyChar keyChar -      @advanceKeyState keyChar -      commands = @keyState.filter (entry) -> entry.command -      @invokeCommand commands[0] if 0 < commands.length -      false # Suppress event. +      @handleKeyChar event, keyChar      else if keyChar and @isCountKey keyChar -      @countPrefix = @countPrefix * 10 + parseInt keyChar +      @reset @countPrefix * 10 + parseInt keyChar        false # Suppress event.      else        @continueBubbling @@ -76,6 +70,12 @@ class KeyHandlerMode extends Mode      else        @continueBubbling +  handleKeyChar: (event, keyChar) -> +    @advanceKeyState keyChar +    commands = @keyState.filter (entry) -> entry.command +    @invokeCommand commands[0] if 0 < commands.length +    false # Suppress event. +    # This returns the first mapping for which keyChar is mapped. The return value is truthy if a match is found    # and falsy otherwise.    mappingForKeyChar: (keyChar) -> @@ -98,9 +98,9 @@ class KeyHandlerMode extends Mode      @reset()      @commandHandler command, countPrefix -  # Reset the state (as if no keys had been handled). -  reset: -> -    @countPrefix = 0 +  # Reset the state (as if no keys had been handled), but retaining the count - if one is provided. +  reset: (count = 0) -> +    @countPrefix = count      @keyState = [@keyMapping]    # This tests whether we are in the reset state.  It is used to check whether we should be using escape to | 
