aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-01-06 13:23:26 +0000
committerStephen Blott2015-01-06 13:23:26 +0000
commitfaf5b35ab501b8c4edc25f484c0b76ee38319f1f (patch)
treefa3379e91cb350d4ae3262b7df9a18b17ab8e997 /content_scripts
parentff88d1707647253cb3b93d3dc79831dc72063feb (diff)
downloadvimium-faf5b35ab501b8c4edc25f484c0b76ee38319f1f.tar.bz2
Modes; simplify PostFindMode.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode_find.coffee19
-rw-r--r--content_scripts/mode_insert.coffee11
2 files changed, 11 insertions, 19 deletions
diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee
index 9a0086a1..0bcb0eb1 100644
--- a/content_scripts/mode_find.coffee
+++ b/content_scripts/mode_find.coffee
@@ -2,8 +2,8 @@
# When we use find mode, the selection/focus can end up in a focusable/editable element. In this situation,
# PostFindMode handles two special cases:
-# 1. Suppress InsertModeTrigger. This prevents keyboard events from dropping us unintentionaly into insert
-# mode. Here, this is achieved by inheriting from InsertModeBlocker.
+# 1. Be an InsertModeBlocker. This prevents keyboard events from dropping us unintentionaly into insert
+# mode. Here, this is achieved by inheriting from InsertModeBlocker.
# 2. If the very-next keystroke is Escape, then drop immediately into insert mode.
#
class PostFindMode extends InsertModeBlocker
@@ -32,16 +32,11 @@ class PostFindMode extends InsertModeBlocker
# Install various ways in which we can leave this mode.
@push
- DOMActive: (event, extra) => @alwaysContinueBubbling => @exit extra
- click: (event, extra) => @alwaysContinueBubbling => @exit extra
- focus: (event, extra) => @alwaysContinueBubbling => @exit extra
- blur: (event, extra) => @alwaysContinueBubbling => @exit extra
- keydown: (event, extra) => @alwaysContinueBubbling => @exit extra if document.activeElement != element
-
- # Inform handlers further down the stack that PostFindMode exited on this event.
- exit: (extra) ->
- extra.postFindModeExited = true if extra
- super()
+ DOMActive: (event) => @alwaysContinueBubbling => @exit()
+ click: (event) => @alwaysContinueBubbling => @exit()
+ focus: (event) => @alwaysContinueBubbling => @exit()
+ blur: (event) => @alwaysContinueBubbling => @exit()
+ keydown: (event) => @alwaysContinueBubbling => @exit() if document.activeElement != element
root = exports ? window
root.PostFindMode = PostFindMode
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index c6f9d5b1..c340c559 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -46,8 +46,8 @@ class InsertMode extends ConstrainedMode
# - When a focusable element receives the focus.
# - When an editable activeElement is clicked. We cannot rely exclusively on focus events for triggering
# insert mode. With find mode, an editable element can be active, but we're not in insert mode (see
-# PostFindMode), and no focus event will be generated. In this case, clicking on the element should
-# activate insert mode (even if the insert-mode blocker is active).
+# PostFindMode), so no focus event will be generated. In this case, clicking on the element should
+# activate insert mode.
#
# This mode is permanently installed fairly low down on the handler stack.
class InsertModeTrigger extends Mode
@@ -71,11 +71,8 @@ class InsertModeTrigger extends Mode
click: (event, extra) =>
@alwaysContinueBubbling =>
unless InsertMode.isActive()
- # We cannot check InsertModeBlocker.isActive(). PostFindMode exits on clicks, so will already have
- # gone. So, instead, it sets an extra we can check.
- if extra?.postFindModeExited
- if document.activeElement == event.target and isEditable event.target
- new InsertMode event.target
+ if document.activeElement == event.target and isEditable event.target
+ new InsertMode event.target
# We may already have focussed something, so check.
new InsertMode document.activeElement if document.activeElement and isFocusable document.activeElement