aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_insert.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/mode_insert.coffee')
-rw-r--r--content_scripts/mode_insert.coffee36
1 files changed, 24 insertions, 12 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index 51ef3d8b..2b0ebb45 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -27,17 +27,19 @@ class InsertMode extends ConstrainedMode
keypress: (event) => @stopBubblingAndTrue
keyup: (event) => @stopBubblingAndTrue
- exit: (extra=null) ->
- if extra?.source == ExitOnEscapeMode and extra?.event?.srcElement?
- element = extra.event.srcElement
- if isFocusable element
+ exit: (extra={}) ->
+ super()
+ if extra.source == ExitOnEscapeMode and extra.event?.srcElement?
+ if isFocusable extra.event.srcElement
# Remove the focus so the user can't just get himself back into insert mode by typing in the same
# input box.
# NOTE(smblott, 2014/12/22) Including embeds for .blur() here is experimental. It appears to be the
# right thing to do for most common use cases. However, it could also cripple flash-based sites and
# games. See discussion in #1211 and #1194.
- element.blur()
- super()
+ extra.event.srcElement.blur()
+
+ # Static method. Return whether insert mode is currently active or not.
+ @isActive: (singleton) -> SingletonMode.isActive InsertMode
# Trigger insert mode:
# - On a keydown event in a contentEditable element.
@@ -55,13 +57,25 @@ class InsertModeTrigger extends Mode
# Some sites (e.g. inbox.google.com) change the contentEditable attribute on the fly (see #1245);
# and unfortunately, the focus event happens *before* the change is made. Therefore, we need to
# check again whether the active element is contentEditable.
- new InsertMode() if document.activeElement?.isContentEditable
+ # NOTE. There's no need to check InsertMode.isActive() here since, if insert mode *is* active,
+ # then we wouldn't be receiving this keyboard event.
+ new InsertMode document.activeElement if document.activeElement?.isContentEditable
@push
focus: (event, extra) =>
@alwaysContinueBubbling =>
- unless extra.suppressInsertModeTrigger?
- new InsertMode event.target if isFocusable event.target
+ unless InsertMode.isActive()
+ unless extra.suppressInsertModeTrigger?
+ new InsertMode event.target if isFocusable event.target
+
+ click: (event, extra) =>
+ @alwaysContinueBubbling =>
+ unless InsertMode.isActive()
+ # 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.
+ 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
@@ -79,9 +93,7 @@ class InsertModeBlocker extends SingletonMode
unless @element?
@push
- focus: (event, extra) =>
- @alwaysContinueBubbling =>
- InsertModeTrigger.suppress extra
+ focus: (event, extra) => @alwaysContinueBubbling => InsertModeTrigger.suppress extra
if @element?.isContentEditable
@push