diff options
| author | Stephen Blott | 2015-01-07 09:57:03 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-07 09:57:03 +0000 |
| commit | 04ac4c64c9634d9f81035ff7e9db537f39b42f3c (patch) | |
| tree | c61e1d5893916b0d3fa191e2aaf285ff7ae9629c /content_scripts/mode_insert.coffee | |
| parent | a7fcfd9a663e2d81a86e5e49e54162399ccb5e6b (diff) | |
| download | vimium-04ac4c64c9634d9f81035ff7e9db537f39b42f3c.tar.bz2 | |
Modes; rework Singletons, InsertModeBlocker and HandlerStack.
This begins work on addressing @philc's comments in #1413. That work is
nevertheless not yet complete.
Diffstat (limited to 'content_scripts/mode_insert.coffee')
| -rw-r--r-- | content_scripts/mode_insert.coffee | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index 960b42f8..83d85fa7 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -55,21 +55,23 @@ class InsertModeTrigger extends Mode super name: "insert-trigger" keydown: (event, extra) => - @alwaysContinueBubbling => - unless InsertModeBlocker.isActive() - # 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 document.activeElement if document.activeElement?.isContentEditable + return @continueBubbling if InsertModeBlocker.isActive extra + # 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. + return @continueBubbling unless document.activeElement?.isContentEditable + new InsertMode document.activeElement + @stopBubblingAndTrue @push focus: (event, extra) => @alwaysContinueBubbling => - unless InsertMode.isActive() or InsertModeBlocker.isActive() + unless InsertMode.isActive() or InsertModeBlocker.isActive extra new InsertMode event.target if isFocusable event.target click: (event, extra) => @alwaysContinueBubbling => + # Do not check InsertModeBlocker.isActive() here. A user click overrides the blocker. unless InsertMode.isActive() if document.activeElement == event.target and isEditable event.target new InsertMode event.target @@ -79,16 +81,16 @@ class InsertModeTrigger extends Mode # Disables InsertModeTrigger. Used by find mode and findFocus to prevent unintentionally dropping into insert # mode on focusable elements. -class InsertModeBlocker extends SingletonMode - constructor: (element, options={}) -> +class InsertModeBlocker extends Mode + constructor: (options={}) -> options.name ||= "insert-blocker" - super InsertModeBlocker, options + super options @push - "blur": (event) => @alwaysContinueBubbling => @exit() if element? and event.srcElement == element + "all": (event, extra) => @alwaysContinueBubbling => extra.isInsertModeBlockerActive = true - # Static method. Return whether the insert-mode blocker is currently active or not. - @isActive: (singleton) -> SingletonMode.isActive InsertModeBlocker + # Static method. Return whether an insert-mode blocker is currently active or not. + @isActive: (extra) -> extra?.isInsertModeBlockerActive root = exports ? window root.InsertMode = InsertMode |
