aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/link_hints.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/link_hints.coffee')
-rw-r--r--content_scripts/link_hints.coffee44
1 files changed, 35 insertions, 9 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