aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-06-03 11:42:25 +0100
committerStephen Blott2015-06-03 11:42:25 +0100
commit03ef7f2a8525e8fbfc67b04d7a0ce47522449d03 (patch)
tree193ab324ab77714f123826ca5c212708c69c0aea /content_scripts/mode.coffee
parentd3e0974640f8138c26b010bd63e3d9caa2ffdfef (diff)
downloadvimium-03ef7f2a8525e8fbfc67b04d7a0ce47522449d03.tar.bz2
Refactor to avoid having to cover all keyboard event cases.
It's pretty common that we want to suppress all keyboard events, so let's support that in modes.coffee, thereby simplifying handlers elsewhere.
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee9
1 files changed, 9 insertions, 0 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index f631b4cd..b2019ef9 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -47,6 +47,15 @@ class Mode
@id = "#{@name}-#{@count}"
@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 to 1) provide handlers for all keyboard events,
+ # and 2) worry about their return value.
+ if options.suppressAllKeyboardEvents
+ for type in [ "keydown", "keypress", "keyup" ]
+ do (type) ->
+ handler = options[type]
+ options[type] = (event) -> handler? event; false
+
@push
keydown: @options.keydown || null
keypress: @options.keypress || null