aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_key_handler.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-12-21 05:09:42 +0000
committerGitHub2016-12-21 05:09:42 +0000
commit320f433afb53cc774b175dab0f6a1ad7a47d60f9 (patch)
tree2bb28d6c6afc7ceeb7f463c6aff23d201b43587b /content_scripts/mode_key_handler.coffee
parentcaa63d6642141d2fe4cd6941ec1e84dd2d3e8225 (diff)
parentedfb7ba3ca148f7b00bd683d1979330f395f2e7e (diff)
downloadvimium-320f433afb53cc774b175dab0f6a1ad7a47d60f9.tar.bz2
Merge pull request #2311 from smblott-github/enterNormalMode
New command option to enter normal mode
Diffstat (limited to 'content_scripts/mode_key_handler.coffee')
-rw-r--r--content_scripts/mode_key_handler.coffee18
1 files changed, 17 insertions, 1 deletions
diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee
index 480a79af..9b5a1fef 100644
--- a/content_scripts/mode_key_handler.coffee
+++ b/content_scripts/mode_key_handler.coffee
@@ -36,6 +36,18 @@ class KeyHandlerMode extends Mode
@mapKeyRegistry = {}
Utils.monitorChromeStorage "mapKeyRegistry", (value) => @mapKeyRegistry = value
+ if options.exitOnEscape
+ # If we're part way through a command's key sequence, then a first Escape should reset the key state,
+ # and only a second Escape should actually exit this mode.
+ @push
+ _name: "key-handler-escape-listener"
+ keydown: (event) =>
+ if KeyboardUtils.isEscape(event) and not @isInResetState()
+ @reset()
+ DomUtils.suppressKeyupAfterEscape handlerStack
+ else
+ @continueBubbling
+
onKeydown: (event) ->
keyChar = KeyboardUtils.getKeyCharString event
keyChar = @mapKeyRegistry[keyChar] ? keyChar
@@ -92,7 +104,10 @@ class KeyHandlerMode extends Mode
# Keystrokes are *never* considered pass keys if the user has begun entering a command. So, for example, if
# 't' is a passKey, then the "t"-s of 'gt' and '99t' are neverthless handled as regular keys.
isPassKey: (keyChar) ->
- @countPrefix == 0 and @keyState.length == 1 and keyChar in (@passKeys ? "")
+ @isInResetState() and keyChar in (@passKeys ? "")
+
+ isInResetState: ->
+ @countPrefix == 0 and @keyState.length == 1
handleKeyChar: (keyChar) ->
bgLog "handle key #{keyChar} (#{@name})"
@@ -106,6 +121,7 @@ class KeyHandlerMode extends Mode
bgLog " invoke #{command.command} count=#{count} "
@reset()
@commandHandler {command, count}
+ @exit() if @options.count? and --@options.count <= 0
@suppressEvent
root = exports ? window