From 50980718d848ca324b6fca0568e2fa7203d51d52 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 5 Jun 2015 05:04:56 +0100 Subject: Fix event suppression for Marks keyboard events. --- content_scripts/mode.coffee | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 9105fabb..ffabc111 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -48,12 +48,11 @@ class Mode @log "activate:", @id # If options.suppressAllKeyboardEvents is truthy, then all keyboard events are suppressed. This avoids - # the need for modes which block all keyboard events 1) to provide handlers for all keyboard events, - # and 2) to worry about their return values. + # the need for modes which suppress all keyboard events 1) to provide handlers for all of those events, + # or 2) to worry about event suppression and event-handler return values. if @options.suppressAllKeyboardEvents for type in [ "keydown", "keypress", "keyup" ] - do (handler = @options[type]) => - @options[type] = (event) => handler? event; @stopBubblingAndFalse + @options[type] = @alwaysSuppressEvent @options[type] @push keydown: @options.keydown || null @@ -179,6 +178,13 @@ class Mode # case), because they do not need to be concerned with the value they yield. alwaysContinueBubbling: handlerStack.alwaysContinueBubbling + # Shorthand for an event handler which always suppresses event propagation. + alwaysSuppressEvent: (handler = null) -> + (event) => + handler? event + DomUtils.suppressPropagation event + @stopBubblingAndFalse + # Activate a new instance of this mode, together with all of its original options (except its main # keybaord-event handlers; these will be recreated). cloneMode: -> -- cgit v1.2.3