aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_insert.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-13 10:07:26 +0000
committerStephen Blott2015-01-13 10:07:26 +0000
commit1191d73c6fea65bcd4ceec807458e81a1a940047 (patch)
treec522c845f317f0fb725ceb121773e89219a52d11 /content_scripts/mode_insert.coffee
parent7684019cb5d5c1d0ac5d7216653613220b4fd8d9 (diff)
downloadvimium-1191d73c6fea65bcd4ceec807458e81a1a940047.tar.bz2
Modes; temporary commit.
Diffstat (limited to 'content_scripts/mode_insert.coffee')
-rw-r--r--content_scripts/mode_insert.coffee31
1 files changed, 17 insertions, 14 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index 5720c901..dd0c8d16 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -73,12 +73,13 @@ triggerSuppressor = new Utils.Suppressor true # Note: true == @continueBubbling
# unintentionally dropping into insert mode on focusable elements.
class InsertModeBlocker extends Mode
constructor: (options = {}) ->
+ defaults =
+ name: "insert-blocker"
+ # The user knows best; so, if the user clicks on something, the insert-mode blocker gets out of the way.
+ exitOnClick: true
+ onClickMode: InsertMode
+ super extend defaults, options
triggerSuppressor.suppress()
- options.name ||= "insert-blocker"
- # See "click" handler below for an explanation of options.onClickMode.
- options.onClickMode ||= InsertMode
- super options
- @onExit -> triggerSuppressor.unsuppress()
@push
_name: "mode-#{@id}/bail-on-click"
@@ -86,15 +87,17 @@ class InsertModeBlocker extends Mode
@alwaysContinueBubbling =>
# The user knows best; so, if the user clicks on something, the insert-mode blocker gets out of the
# way.
- @exit event
- # However, there's a corner case. If the active element is focusable, then, had we not been
- # blocking the trigger, we would already have been in insert mode. Now, a click on that element
- # will not generate a new focus event, so the insert-mode trigger will not fire. We have to handle
- # this case specially. @options.onClickMode specifies the mode to use (by default, insert mode).
- if document.activeElement and
- event.target == document.activeElement and DomUtils.isEditable document.activeElement
- new @options.onClickMode
- targetElement: document.activeElement
+
+ exit: ->
+ super()
+ # If the element associated with the event is focusable, then, had we not been blocking the trigger, we
+ # would already have been in insert mode. Now, a click on that element will not generate a new focus
+ # event, so the insert-mode trigger will not fire. We have to handle this case specially.
+ # @options.onClickMode specifies the mode to use (by default, insert mode).
+ if @clickEvent?.target? and DomUtils.isFocusable @clickEvent.target
+ new @options.onClickMode
+ targetElement: event.target
+ triggerSuppressor.unsuppress()
root = exports ? window
root.InsertMode = InsertMode