diff options
| -rw-r--r-- | content_scripts/link_hints.coffee | 44 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 10 | ||||
| -rw-r--r-- | lib/settings.coffee | 1 |
3 files changed, 43 insertions, 12 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index db8fe300..b33bf3ce 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -367,7 +367,7 @@ class LinkHintsMode if linksMatched.length == 0 @deactivateMode() else if linksMatched.length == 1 - @activateLink linksMatched[0], keyResult.delay ? 0 + @activateLink linksMatched[0], keyResult.delay ? 0, keyResult.waitForEnter and Settings.get "waitForEnterForFilteredHints" else @hideMarker marker for marker in hintMarkers @showMarker matched, @markerMatcher.hintKeystrokeQueue.length for matched in linksMatched @@ -375,7 +375,7 @@ class LinkHintsMode # # When only one link hint remains, this function activates it in the appropriate way. # - activateLink: (matchedLink, delay = 0) -> + activateLink: (matchedLink, delay = 0, waitForEnter = false) -> clickEl = matchedLink.clickableItem if (DomUtils.isSelectable(clickEl)) DomUtils.simulateSelect(clickEl) @@ -384,12 +384,18 @@ class LinkHintsMode # TODO figure out which other input elements should not receive focus if (clickEl.nodeName.toLowerCase() == "input" and clickEl.type not in ["button", "submit"]) clickEl.focus() - DomUtils.flashRect(matchedLink.rect) - @linkActivator(clickEl) - if @mode is OPEN_WITH_QUEUE - @deactivateMode delay, -> LinkHints.activateModeWithQueue() - else - @deactivateMode delay + + linkActivator = => + @linkActivator(clickEl) + LinkHints.activateModeWithQueue() if @mode is OPEN_WITH_QUEUE + + delay = 0 if waitForEnter + @deactivateMode delay, => + if waitForEnter + new WaitForEnter matchedLink.rect, linkActivator + else + DomUtils.flashRect matchedLink.rect + linkActivator() # # Shows the marker, highlighting matchingCharCount characters. @@ -571,7 +577,7 @@ class FilterHints @activeHintMarker = linksMatched[tabCount] @activeHintMarker?.classList.add "vimiumActiveHintMarker" - { linksMatched: linksMatched, delay: delay } + { linksMatched: linksMatched, delay: delay, waitForEnter: 0 < delay } pushKeyChar: (keyChar, keydownKeyChar) -> # For filtered hints, we *always* use the keyChar value from keypress, because there is no obvious and @@ -659,5 +665,25 @@ class TypingProtector extends Mode @onExit callback +class WaitForEnter extends Mode + constructor: (rect, callback) -> + super + name: "hint/wait-for-enter" + suppressAllKeyboardEvents: true + exitOnEscape: true + indicator: "Hit <Enter> to proceed..." + + @push + keydown: (event) => + if event.keyCode == keyCodes.enter + @exit() + callback() + DomUtils.suppressEvent event + else + true + + flashEl = DomUtils.addFlashRect rect + @onExit -> DomUtils.removeElement flashEl + root = exports ? window root.LinkHints = LinkHints diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 7473df17..db90c43a 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -262,8 +262,7 @@ DomUtils = # but Webkit will. Dispatching a click on an input box does not seem to focus it; we do that separately element.dispatchEvent(mouseEvent) - # momentarily flash a rectangular border to give user some visual feedback - flashRect: (rect) -> + addFlashRect: (rect) -> flashEl = @createElement "div" flashEl.id = "vimiumFlash" flashEl.className = "vimiumReset" @@ -271,7 +270,12 @@ DomUtils = flashEl.style.top = rect.top + window.scrollY + "px" flashEl.style.width = rect.width + "px" flashEl.style.height = rect.height + "px" - document.documentElement.appendChild(flashEl) + document.documentElement.appendChild flashEl + flashEl + + # momentarily flash a rectangular border to give user some visual feedback + flashRect: (rect) -> + flashEl = @addFlashRect rect setTimeout((-> DomUtils.removeElement flashEl), 400) suppressPropagation: (event) -> diff --git a/lib/settings.coffee b/lib/settings.coffee index 79ee04a9..a33a88e8 100644 --- a/lib/settings.coffee +++ b/lib/settings.coffee @@ -170,6 +170,7 @@ Settings = newTabUrl: "chrome://newtab" grabBackFocus: false regexFindMode: false + waitForEnterForFilteredHints: true # Once properly implmented, this will default to false. settingsVersion: Utils.getCurrentVersion() helpDialog_showAdvancedCommands: false |
