From 33d9699a9a5645c5752c6e8c9394101e7b4bbbbe Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Oct 2015 09:12:40 +0100 Subject: Suppress trailing key events (after link hints). This ensures that -- on leaving link hints mode -- we consume any trailing keyup events (and don't let the underlying page see them). Additional notes: - There are other places where we seem to be leaking keyup events. - A separate bug... It looks like we're calling `exit()` on link-hints mode twice. --- content_scripts/link_hints.coffee | 1 + content_scripts/mode.coffee | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'content_scripts') 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..49da03e2 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -144,6 +144,25 @@ class Mode keyup: (event) => if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue + # if @options.suppressTrailingKeyEvents is set, then 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() -- cgit v1.2.3 From 1c1bfb8d070ccbae1307c40e0b0a12afb6f65219 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Oct 2015 10:07:12 +0100 Subject: Make comment/explanation match implementation. --- content_scripts/mode.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 49da03e2..cab97b32 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -144,10 +144,10 @@ class Mode keyup: (event) => if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue - # if @options.suppressTrailingKeyEvents is set, then 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 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) -> -- cgit v1.2.3 From 7158cd670ae5824ebeb134fe3ec35472e4dc692f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Oct 2015 12:22:18 +0100 Subject: Make mode.exit() idempotent. We've been calling hintMode.exit() twice: once explicitly, and once as a side effect of the simulated click event. Since there are so many code paths through link hints, it seems better to simply explicitly make mode.exit() idempotent for all modes. Which is what this commit does. --- content_scripts/mode.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index cab97b32..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 @@ -189,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() -- cgit v1.2.3