diff options
| author | Stephen Blott | 2016-02-28 11:07:21 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-03-05 05:38:30 +0000 |
| commit | 6e37f605fe45ee5eca03153c35c55c231e703c95 (patch) | |
| tree | 1d73306bf8aebf2055786ea6bb18b8c94073b905 /content_scripts | |
| parent | f0c0a07a2dcb7c73f6aa93de166d8fa87e21f305 (diff) | |
| download | vimium-6e37f605fe45ee5eca03153c35c55c231e703c95.tar.bz2 | |
Key bindings; minor tweaks.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode.coffee | 3 | ||||
| -rw-r--r-- | content_scripts/mode_key_handler.coffee | 25 |
2 files changed, 7 insertions, 21 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index efbc9cf4..8a84457e 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -119,8 +119,7 @@ class Mode @deactivateSingleton @options.singleton singletons[key] = this - # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys, - # and calls @registerStateChange() (if defined) whenever the state changes. + # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys. if @options.trackState @enabled = false @passKeys = "" 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) |
