aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-10 18:52:24 +0000
committerStephen Blott2015-01-10 18:52:24 +0000
commit80ad0bc3087a3bf00d61bdd6c9cf48e971e22480 (patch)
tree76eaa3b86be1c6ac130724168d0bf3bbbb6849c5 /content_scripts/mode.coffee
parent704ae28629154a732e20e16d56b23af265d51b85 (diff)
downloadvimium-80ad0bc3087a3bf00d61bdd6c9cf48e971e22480.tar.bz2
Modes; re-architect key suppression and passkeys.
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee33
1 files changed, 26 insertions, 7 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 19354d94..0fcab675 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -111,16 +111,18 @@ class Mode
@passKeys = passKeys
@registerStateChange?()
- # If @options.suppressPrintableEvents is truthy, then it should be an element. All printable keyboard
- # events on that element are suppressed, if necessary (that is, *after* bubbling down the handler stack).
- # We only suppress keypress events. This is used by PostFindMode to protect active, editable elements.
- # Note: We use unshift here, not push, so the handler is installed at the bottom of the stack.
+ # 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.
if @options.suppressPrintableEvents
- @unshift
+ @push
_name: "mode-#{@id}/suppressPrintableEvents"
keypress: (event) =>
- if KeyboardUtils.isPrintable(event) and
- event.srcElement == @options.suppressPrintableEvents then @suppressEvent else @continueBubbling
+ @alwaysContinueBubbling =>
+ if event.srcElement == @options.suppressPrintableEvents
+ if KeyboardUtils.isPrintable(event)
+ event.vimium_suppress_event = true
Mode.updateBadge() if @badge
Mode.modes.push @
@@ -217,6 +219,9 @@ new class BadgeMode extends Mode
name: "badge"
trackState: true
+ # FIXME(smblott) BadgeMode is currently triggering and updateBadge event on every focus event. That's a
+ # lot, considerably more than is necessary. Really, it only needs to trigger when we change frame, or
+ # when we change tab.
@push
_name: "mode-#{@id}/focus"
"focus": => @alwaysContinueBubbling -> Mode.updateBadge()
@@ -228,5 +233,19 @@ 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 also 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