diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/link_hints.coffee | 1 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 26 |
2 files changed, 25 insertions, 2 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() |
