diff options
| author | Stephen Blott | 2015-01-03 13:20:04 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-03 13:20:04 +0000 |
| commit | baccd7c5cef14480e21e41519e20ee19fa238655 (patch) | |
| tree | 26f1252bd952d0a2ab3b88259768cdcd30f0c26a /content_scripts/vimium_frontend.coffee | |
| parent | 00573389c63cebb42c225e10786aeb05e72fab39 (diff) | |
| download | vimium-baccd7c5cef14480e21e41519e20ee19fa238655.tar.bz2 | |
Modes; Fix various mode changes.
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 0f23af05..da479781 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -113,11 +113,9 @@ class NormalMode extends Mode keypress: onKeypress keyup: onKeyup - updateBadgeForMode: (badge) -> - handlerStack.alwaysContinueBubbling => - # Idea... Instead of an icon, we could show the keyQueue here (if it's non-empty). - super badge - badge.badge = "" unless isEnabledForUrl + chooseBadge: (badge) -> + super badge + badge.badge = "" unless isEnabledForUrl # # Complete initialization work that sould be done prior to DOMReady. @@ -136,8 +134,10 @@ initializePreDomReady = -> # Install passKeys and insert modes. These too are permanently on the stack (although not always active). # Note. There's no need to explicitly Mode.updateBadge(). The new InsertMode() updates the badge. + # Note. There's no need to explicitly Mode.updateBadge(). The new InsertMode() updates the badge. passKeysMode = new PassKeysMode() insertMode = new InsertMode() + Mode.updateBadge() checkIfEnabledForUrl() @@ -740,10 +740,10 @@ class FindMode extends Mode handleEscapeForFindMode() @exit() @suppressEvent - else if (event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey) + else if event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey handleDeleteForFindMode() @suppressEvent - else if (event.keyCode == keyCodes.enter) + else if event.keyCode == keyCodes.enter handleEnterForFindMode() @exit() @suppressEvent @@ -761,24 +761,44 @@ 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 +# If find lands in an editable element then: +# - "Esc" drops us into insert mode. +# - Subsequent command keypresses should not cause us to drop into insert mode. +count = 0 +class PostFindMode extends SingletonMode + constructor: -> + element = document.activeElement + handleKeydownEscape = true + super PostFindMode, keydown: (event) => - @exit() - if (KeyboardUtils.isEscape(event)) - DomUtils.simulateSelect(document.activeElement) - insertMode.activate() + if handleKeydownEscape and KeyboardUtils.isEscape event + DomUtils.simulateSelect document.activeElement + insertMode.activate element + @exit() 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 + console.log "suppress", event + handleKeydownEscape = false + InsertMode.suppressKeydownTrigger event + # We can safely exit if element is contentEditable. Keystrokes will never cause us to drop into + # insert mode anyway. + @exit() if element.isContentEditable + @continueBubbling + keypress: => @continueBubbling + keyup: => @continueBubbling + + console.log ++count, "PostFindMode create" + canTakeInput = element and DomUtils.isSelectable(element) and isDOMDescendant findModeAnchorNode, element + canTakeInput ||= element?.isContentEditable + return @exit() unless canTakeInput + + @handlers.push handlerStack.push + DOMActive: (event) => @exit() + focus: (event) => @exit() + blur: (event) => @exit() + + exit: -> + console.log ++count, "exit PostFindMode" + super() performFindInPlace = -> cachedScrollX = window.scrollX @@ -807,7 +827,7 @@ executeFind = (query, options) -> HUD.hide(true) # ignore the selectionchange event generated by find() document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true) - Mode.runIn FocusMustNotTriggerInsertMode, -> + Mode.runIn InsertModeSuppressFocusTrigger, -> result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false) setTimeout( -> document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true) |
