diff options
| author | Stephen Blott | 2015-01-07 11:29:24 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-07 16:38:50 +0000 |
| commit | 0429da577097bd7d30d12901fcc74385e44d83f4 (patch) | |
| tree | 2b307ac9f28273a2f93623724877e766b9f7745c /content_scripts/mode_find.coffee | |
| parent | 04ac4c64c9634d9f81035ff7e9db537f39b42f3c (diff) | |
| download | vimium-0429da577097bd7d30d12901fcc74385e44d83f4.tar.bz2 | |
Modes; Continue incorporation of comments in #1413.
- Slight rework of HandlerStack.
- Remove classs ExitOnEscape and ExitOnBlur
- Rework InsertMode, plus trigger and blocker.
- Remove StateMode.
- Do no mixin options.
- Lots of tidy up (including set a debug variable to Mode).
Diffstat (limited to 'content_scripts/mode_find.coffee')
| -rw-r--r-- | content_scripts/mode_find.coffee | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 18cb7b71..f9766e3a 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -3,26 +3,24 @@ # 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. Be an InsertModeBlocker. This prevents keyboard events from dropping us unintentionaly into insert -# mode. Here, this is achieved by inheriting from InsertModeBlocker. +# mode. 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 constructor: (findModeAnchorNode) -> - element = document.activeElement - super name: "post-find" singleton: PostFindMode + element = document.activeElement return @exit() unless element and findModeAnchorNode # Special cases only arise if the active element can take input. So, exit immediately if it cannot not. canTakeInput = DomUtils.isSelectable(element) and DomUtils.isDOMDescendant findModeAnchorNode, element canTakeInput ||= element.isContentEditable - canTakeInput ||= findModeAnchorNode?.parentElement?.isContentEditable + canTakeInput ||= findModeAnchorNode.parentElement?.isContentEditable return @exit() unless canTakeInput - self = @ @push keydown: (event) -> if element == document.activeElement and KeyboardUtils.isEscape event @@ -33,13 +31,18 @@ class PostFindMode extends InsertModeBlocker @remove() true - # Install various ways in which we can leave this mode. + # Various ways in which we can leave PostFindMode. @push - DOMActive: (event) => @alwaysContinueBubbling => @exit() - click: (event) => @alwaysContinueBubbling => @exit() focus: (event) => @alwaysContinueBubbling => @exit() blur: (event) => @alwaysContinueBubbling => @exit() keydown: (event) => @alwaysContinueBubbling => @exit() if document.activeElement != element + # If element is selectable, then it's already focused. If the user clicks on it, then there's no new + # focus event, so InsertModeTrigger doesn't fire and we don't drop automatically into insert mode. + click: (event) => + @alwaysContinueBubbling => + new InsertMode event.target if DomUtils.isDOMDescendant element, event.target + @exit() + root = exports ? window root.PostFindMode = PostFindMode |
