aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2016-02-27 17:33:05 +0000
committerStephen Blott2016-03-05 05:38:29 +0000
commit18b8db13fa5184e0cc3ac5fd6645620fdb9d5cef (patch)
tree260ecbb0b01bf6bae2feb882d69258a705728111 /content_scripts
parent93901aeecc842e563ea95ca3cb1b4e5d396f25dd (diff)
downloadvimium-18b8db13fa5184e0cc3ac5fd6645620fdb9d5cef.tar.bz2
Key bindings; tweaks and fixes.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode_key_handler.coffee24
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