aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-10-10 07:24:54 +0100
committerStephen Blott2015-10-10 07:24:54 +0100
commit85e12c5006a11fec9790fc6725e8078ecdbc198f (patch)
treeed1611d45aea5525157022192880c3c29eab9e8e /content_scripts/mode.coffee
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).
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee26
1 files changed, 24 insertions, 2 deletions
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()