diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_key_handler.coffee | 24 |
1 files changed, 12 insertions, 12 deletions
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 |
