aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_key_handler.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-02-28 11:07:21 +0000
committerStephen Blott2016-03-05 05:38:30 +0000
commit6e37f605fe45ee5eca03153c35c55c231e703c95 (patch)
tree1d73306bf8aebf2055786ea6bb18b8c94073b905 /content_scripts/mode_key_handler.coffee
parentf0c0a07a2dcb7c73f6aa93de166d8fa87e21f305 (diff)
downloadvimium-6e37f605fe45ee5eca03153c35c55c231e703c95.tar.bz2
Key bindings; minor tweaks.
Diffstat (limited to 'content_scripts/mode_key_handler.coffee')
-rw-r--r--content_scripts/mode_key_handler.coffee25
1 files changed, 6 insertions, 19 deletions
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)