From f2bced459457dcc962d4bafe2fdf2e6245506ee3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 16:07:25 +0000 Subject: Key bindings; tweaks. --- content_scripts/mode.coffee | 2 +- content_scripts/mode_key_handler.coffee | 18 +++++++----------- content_scripts/vimium_frontend.coffee | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 8a84457e..3327b58f 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -125,7 +125,7 @@ class Mode @passKeys = "" @push _name: "mode-#{@id}/registerStateChange" - registerStateChange: ({ enabled: @enabled, passKeys: @passKeys }) => @alwaysContinueBubbling => + registerStateChange: ({ enabled: @enabled, passKeys: @passKeys }) => @continueBubbling # If @options.passInitialKeyupEvents is set, then we pass initial non-printable keyup events to the page # or to other extensions (because the corresponding keydown events were passed). This is used when diff --git a/content_scripts/mode_key_handler.coffee b/content_scripts/mode_key_handler.coffee index 97966644..567552c0 100644 --- a/content_scripts/mode_key_handler.coffee +++ b/content_scripts/mode_key_handler.coffee @@ -1,31 +1,27 @@ class KeyHandlerMode extends Mode - countPrefix: 0 keydownEvents: {} - keyState: [] + setKeyMapping: (@keyMapping) -> @reset() constructor: (options) -> @commandHandler = options.commandHandler ? (->) @setKeyMapping options.keyMapping ? {} - delete options[option] for option in ["commandHandler", "keyMapping"] super extend options, keydown: @onKeydown.bind this keypress: @onKeypress.bind this keyup: @onKeyup.bind this - # We cannot track matching keydown/keyup events if we lose the focus. + # We cannot track keyup events if we lose the focus. blur: (event) => @alwaysContinueBubbling => @keydownEvents = {} if event.target == window - setKeyMapping: (@keyMapping) -> @reset() - onKeydown: (event) -> keyChar = KeyboardUtils.getKeyCharString event if KeyboardUtils.isEscape event if @countPrefix == 0 and @keyState.length == 1 @continueBubbling else + @keydownEvents[event.keyCode] = true @reset() - DomUtils.suppressKeyupAfterEscape handlerStack false # Suppress event. else if keyChar and @mappingForKeyChar keyChar @keydownEvents[event.keyCode] = true @@ -33,10 +29,10 @@ class KeyHandlerMode extends Mode else if keyChar @continueBubbling else if (keyChar = KeyboardUtils.getKeyChar event) and (@mappingForKeyChar(keyChar) or @isCountKey keyChar) - # 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. - DomUtils.suppressPropagation event + # We will probably be handling a subsequent keypress event, so suppress propagation of this event to + # prevent triggering page event listeners (e.g. Google instant Search). @keydownEvents[event.keyCode] = true + DomUtils.suppressPropagation event @stopBubblingAndTrue else @continueBubbling @@ -69,7 +65,7 @@ class KeyHandlerMode extends Mode countPrefix = if 0 < @countPrefix then @countPrefix else 1 @reset() bgLog "Calling mode=#{@name}, command=#{commands[0].command}, count=#{countPrefix}." - @commandHandler commands[0], countPrefix + @commandHandler command: commands[0], count: countPrefix, event: event false # Suppress event. # This returns the first key-state entry for which keyChar is mapped. The return value is truthy if a match diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index e821b136..ec666a23 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -107,13 +107,13 @@ class NormalMode extends KeyHandlerMode if area == "local" and changes.normalModeKeyStateMapping?.newValue @setKeyMapping changes.normalModeKeyStateMapping.newValue - commandHandler: (registryEntry, count) -> + commandHandler: ({command: registryEntry, count, event}) -> count *= registryEntry.options.count ? 1 count = 1 if registryEntry.noRepeat if registryEntry.repeatLimit? and registryEntry.repeatLimit < count return unless confirm """ - You have asked Vimium to perform #{count} repeats of the command: #{registryEntry.description}.\n + You have asked Vimium to perform #{count} repetitions of the command: #{registryEntry.description}.\n Are you sure you want to continue?""" if registryEntry.isBackgroundCommand -- cgit v1.2.3