From 0dbc181e577d0699fd25fd5f5f39e2ffb35a4f07 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 12 Jan 2015 07:50:50 +0000 Subject: Modes; re-work key suppression for PostFindMode. --- content_scripts/mode.coffee | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 1c6cddb1..94854b74 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -114,15 +114,17 @@ class Mode # If @options.suppressPrintableEvents is truthy, then it should be an element. All printable keypress # events on that element are suppressed, if necessary. They are suppressed *after* bubbling down the # handler stack and finding no handler. This is used by PostFindMode to protect active, editable - # elements. + # elements. Note, this handler is installed with unshift (not push), so it ends is installed at the + # *bottom* of the handler stack, and sees keyboard events only after other modes (notably, normal mode) + # have not handled them. if @options.suppressPrintableEvents - @push + @unshift _name: "mode-#{@id}/suppressPrintableEvents" keypress: (event) => - @alwaysContinueBubbling => - if event.srcElement == @options.suppressPrintableEvents - if KeyboardUtils.isPrintable event - event.vimium_suppress_event = true + if event.srcElement == @options.suppressPrintableEvents and KeyboardUtils.isPrintable event + @suppressEvent + else + @continueBubbling Mode.updateBadge() if @badge Mode.modes.push @ @@ -235,20 +237,5 @@ new class BadgeMode extends Mode registerStateChange: -> Mode.updateBadge() -# KeySuppressor is a pseudo mode (near the bottom of the stack) which suppresses keyboard events tagged with -# the "vimium_suppress_event" property. This allows modes higher up in the stack to tag events for -# suppression, but only after verifying that no other mode (notably, normal mode) wants to handle the event. -# Note. We create the the one-and-only instance here. -new class KeySuppressor extends Mode - constructor: -> - super - name: "key-suppressor" - keydown: (event) => @handle event - keypress: (event) => @handle event - keyup: (event) => @handle event - - handle: (event) -> - if event.vimium_suppress_event then @suppressEvent else @continueBubbling - root = exports ? window root.Mode = Mode -- cgit v1.2.3