aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-10-10 07:24:54 +0100
committerStephen Blott2015-10-10 07:24:54 +0100
commit85e12c5006a11fec9790fc6725e8078ecdbc198f (patch)
treeed1611d45aea5525157022192880c3c29eab9e8e
parentffc662a8dcff176bb58f008ab5142fb91802dd7c (diff)
parent7158cd670ae5824ebeb134fe3ec35472e4dc692f (diff)
downloadvimium-85e12c5006a11fec9790fc6725e8078ecdbc198f.tar.bz2
Merge pull request #1849 from smblott-github/suppress-trailing-key-events
Suppress trailing key events (after link hints).
-rw-r--r--content_scripts/link_hints.coffee1
-rw-r--r--content_scripts/mode.coffee26
-rw-r--r--lib/handler_stack.coffee2
3 files changed, 26 insertions, 3 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index a5e94fd0..cdd2dfac 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -69,6 +69,7 @@ class LinkHintsMode
indicator: false
passInitialKeyupEvents: true
suppressAllKeyboardEvents: true
+ suppressTrailingKeyEvents: true
exitOnEscape: true
exitOnClick: true
exitOnScroll: true
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 508b1b2c..c7c6bd55 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -41,6 +41,7 @@ class Mode
@handlers = []
@exitHandlers = []
@modeIsActive = true
+ @modeIsExiting = false
@name = @options.name || "anonymous"
@count = ++count
@@ -144,6 +145,25 @@ class Mode
keyup: (event) =>
if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue
+ # if @options.suppressTrailingKeyEvents is set, then -- on exit -- we suppress all key events until a
+ # subsquent (non-repeat) keydown or keypress. In particular, the intention is to catch keyup events for
+ # keys which we have handled, but which otherwise might trigger page actions (if the page is listening for
+ # keyup events).
+ if @options.suppressTrailingKeyEvents
+ @onExit ->
+ handler = (event) ->
+ if event.repeat
+ false # Suppress event.
+ else
+ keyEventSuppressor.exit()
+ true # Do not suppress event.
+
+ keyEventSuppressor = new Mode
+ name: "suppress-trailing-key-events"
+ keydown: handler
+ keypress: handler
+ keyup: -> handlerStack.stopBubblingAndFalse
+
Mode.modes.push @
@setIndicator()
@logModes()
@@ -170,8 +190,10 @@ class Mode
exit: ->
if @modeIsActive
@log "deactivate:", @id
- handler() for handler in @exitHandlers
- handlerStack.remove handlerId for handlerId in @handlers
+ unless @modeIsExiting
+ @modeIsExiting = true
+ handler() for handler in @exitHandlers
+ handlerStack.remove handlerId for handlerId in @handlers
Mode.modes = Mode.modes.filter (mode) => mode != @
@modeIsActive = false
@setIndicator()
diff --git a/lib/handler_stack.coffee b/lib/handler_stack.coffee
index b09d3183..c07d028b 100644
--- a/lib/handler_stack.coffee
+++ b/lib/handler_stack.coffee
@@ -48,7 +48,7 @@ class HandlerStack
result = handler[type].call @, event
@logResult eventNumber, type, event, handler, result if @debug
if not result
- DomUtils.suppressEvent event if @isChromeEvent event
+ DomUtils.suppressEvent event if @isChromeEvent event
return false
return true if result == @stopBubblingAndTrue
return false if result == @stopBubblingAndFalse