diff options
| author | Stephen Blott | 2015-01-12 07:50:50 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-12 07:50:50 +0000 |
| commit | 0dbc181e577d0699fd25fd5f5f39e2ffb35a4f07 (patch) | |
| tree | 1cc014975101fa9e6dfdc713070aecbef2c1207b | |
| parent | c5f3abacb27afd2c014a18bede8e6281e272a14a (diff) | |
| download | vimium-0dbc181e577d0699fd25fd5f5f39e2ffb35a4f07.tar.bz2 | |
Modes; re-work key suppression for PostFindMode.
| -rw-r--r-- | content_scripts/mode.coffee | 29 |
1 files changed, 8 insertions, 21 deletions
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 |
