aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_key_handler.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-02-27 15:03:09 +0000
committerStephen Blott2016-03-05 05:37:40 +0000
commit47de80f2fcb03c8741ab46308ce982209f74f6ac (patch)
treec9070f1e1777ddef4f10bf91280d88114704408a /content_scripts/mode_key_handler.coffee
parent3f63ceb19046157692eac9e9a13486af7e50a57e (diff)
downloadvimium-47de80f2fcb03c8741ab46308ce982209f74f6ac.tar.bz2
Key bindings; fix passkeys.
Diffstat (limited to 'content_scripts/mode_key_handler.coffee')
-rw-r--r--content_scripts/mode_key_handler.coffee20
1 files changed, 13 insertions, 7 deletions
diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee
index 6e04addb..7f03dd64 100644
--- a/content_scripts/mode_key_handler.coffee
+++ b/content_scripts/mode_key_handler.coffee
@@ -35,7 +35,7 @@ class KeyHandlerMode extends Mode
DomUtils.suppressKeyupAfterEscape handlerStack
false # Suppress event.
- else if keyChar and @keyCharIsKeyStatePrefix keyChar
+ else if keyChar and @mappingForKeyChar keyChar
@advanceKeyState keyChar
commands = @keyState.filter (entry) -> "string" == typeof entry
@invokeCommand commands[0] if 0 < commands.length
@@ -46,7 +46,7 @@ class KeyHandlerMode extends Mode
# handling that event, then we need to suppress propagation of this keydown event to prevent triggering
# page features like Google instant search.
keyChar = KeyboardUtils.getKeyChar event
- if keyChar and (@keyCharIsKeyStatePrefix(keyChar) or @isCountKey keyChar)
+ if keyChar and (@mappingForKeyChar(keyChar) or @isCountKey keyChar)
DomUtils.suppressPropagation event
@keydownEvents[@getEventCode event] = true
@stopBubblingAndTrue
@@ -56,7 +56,7 @@ class KeyHandlerMode extends Mode
onKeypress: (event) ->
keyChar = KeyboardUtils.getKeyCharString event
- if keyChar and @keyCharIsKeyStatePrefix keyChar
+ if keyChar and @mappingForKeyChar keyChar
@advanceKeyState keyChar
commands = @keyState.filter (entry) -> entry.command
@invokeCommand commands[0] if 0 < commands.length
@@ -76,11 +76,12 @@ class KeyHandlerMode extends Mode
else
@continueBubbling
- # This tests whether keyChar is a prefix of any current mapping in the key state.
- keyCharIsKeyStatePrefix: (keyChar) ->
+ # 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) ->
for mapping in @keyState
- return true if keyChar of mapping
- false
+ return mapping if keyChar of mapping
+ null
# This is called whenever a keyChar is matched. We keep any existing entries matching keyChar, and append a
# new copy of the global key mappings.
@@ -115,6 +116,11 @@ class KeyHandlerMode extends Mode
else
'1' <= keyChar <= '9'
+ # True if keyChar would be the first character of a command mapping. This is used by passKeys to decide
+ # whether keyChar is a continuation of a command which the user has already begin entering.
+ isFirstKeyChar: (keyChar) ->
+ @countPrefix == 0 and @keyMapping == @mappingForKeyChar keyChar
+
getEventCode: (event) -> event.keyCode
root = exports ? window