diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_insert.coffee | 1 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 36 |
2 files changed, 23 insertions, 14 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index 64aaa445..ed5d0023 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -50,6 +50,7 @@ class InsertMode extends Mode super name: "insert" keydown: (event) => + return @continueBubbling if event.suppressInsertMode return @continueBubbling unless @isActive() return @stopBubblingAndTrue unless KeyboardUtils.isEscape event # We're now exiting insert mode. diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index a252c878..0f23af05 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -726,6 +726,8 @@ handleEnterForFindMode = -> focusFoundLink() document.body.classList.add("vimiumFindMode") settings.set("findModeRawQuery", findModeQuery.rawQuery) + # If we have found an input element, the pressing <esc> immediately afterwards sends us into insert mode. + new PostFindMode() class FindMode extends Mode constructor: (badge="F") -> @@ -759,6 +761,25 @@ class FindMode extends Mode Mode.updateBadge() +# If find lands in an editable element, then "Esc" drops us into insert mode. +class PostFindMode extends Mode + constructor: (element) -> + super + keydown: (event) => + @exit() + if (KeyboardUtils.isEscape(event)) + DomUtils.simulateSelect(document.activeElement) + insertMode.activate() + return @suppressEvent # we have "consumed" this event, so do not propagate + event.suppressInsertMode = true + return @continueBubbling + + elementCanTakeInput = document.activeElement && + DomUtils.isSelectable(document.activeElement) && + isDOMDescendant(findModeAnchorNode, document.activeElement) + elementCanTakeInput ||= document.activeElement?.isContentEditable + @exit() unless elementCanTakeInput + performFindInPlace = -> cachedScrollX = window.scrollX cachedScrollY = window.scrollY @@ -855,20 +876,7 @@ findAndFocus = (backwards) -> # if we have found an input element via 'n', pressing <esc> immediately afterwards sends us into insert # mode - elementCanTakeInput = document.activeElement && - DomUtils.isSelectable(document.activeElement) && - isDOMDescendant(findModeAnchorNode, document.activeElement) - if (elementCanTakeInput) - handlerStack.push({ - keydown: (event) -> - @remove() - if (KeyboardUtils.isEscape(event)) - DomUtils.simulateSelect(document.activeElement) - enterInsertModeWithoutShowingIndicator(document.activeElement) - insertMode.activate() - return false # we have "consumed" this event, so do not propagate - return true - }) + new PostFindMode() focusFoundLink() |
