aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/link_hints.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-14 07:57:09 +0000
committerStephen Blott2015-01-14 09:46:00 +0000
commit9b0a48955c61c262cc4428b2360938d4b54d2d41 (patch)
tree3abda5d154e96ad019eb9aa67ff59a362775fa23 /content_scripts/link_hints.coffee
parent7e1c3475ed9241a5e1fbf78b8134e6ed669ea906 (diff)
downloadvimium-9b0a48955c61c262cc4428b2360938d4b54d2d41.tar.bz2
Modes; substantial reworking of insert mode (and friends).
Diffstat (limited to 'content_scripts/link_hints.coffee')
-rw-r--r--content_scripts/link_hints.coffee37
1 files changed, 15 insertions, 22 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index b0feea8c..5e95ef99 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -8,9 +8,10 @@
# In 'filter' mode, our link hints are numbers, and the user can narrow down the range of possibilities by
# typing the text of the link itself.
#
-# The "name" property here is a short-form name to appear in the link-hints mode name. Debugging only. The
+# The "name" property below is a short-form name to appear in the link-hints mode name. Debugging only. The
# key appears in the mode's badge.
# NOTE(smblott) The use of keys in badges is experimental. It may prove too noisy.
+#
OPEN_IN_CURRENT_TAB = { name: "curr-tab", key: "" }
OPEN_IN_NEW_BG_TAB = { name: "bg-tab", key: "B" }
OPEN_IN_NEW_FG_TAB = { name: "fg-tab", key: "F" }
@@ -65,21 +66,13 @@ LinkHints =
@hintMarkerContainingDiv = DomUtils.addElementList(hintMarkers,
{ id: "vimiumHintMarkerContainer", className: "vimiumReset" })
- @handlerMode =
- new class HintMode extends Mode
- constructor: ->
- super
- name: "hint/#{mode.name}"
- badge: "#{mode.key}?"
- exitOnEscape: true
- keydown: (event) -> LinkHints.onKeyDownInMode hintMarkers, event
- # trap all other keyboard events
- keypress: => @stopBubblingAndFalse
- keyup: => @stopBubblingAndFalse
-
- exit: (delay, callback) =>
- LinkHints.deactivateMode delay, callback
- super()
+ @hintMode = new Mode
+ name: "hint/#{mode.name}"
+ badge: "#{mode.key}?"
+ keydown: @onKeyDownInMode.bind(this, hintMarkers),
+ # trap all key events
+ keypress: -> false
+ keyup: -> false
setOpenLinkMode: (@mode) ->
if @mode is OPEN_IN_NEW_BG_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE
@@ -278,14 +271,13 @@ LinkHints =
# TODO(philc): Ignore keys that have modifiers.
if (KeyboardUtils.isEscape(event))
- # TODO(smblott). Now unreachable. Clean up. Left like this for now to keep the diff clean.
- @handlerMode.exit()
+ @deactivateMode()
else
keyResult = @getMarkerMatcher().matchHintsByKey(hintMarkers, event)
linksMatched = keyResult.linksMatched
delay = keyResult.delay ? 0
if (linksMatched.length == 0)
- @handlerMode.exit()
+ @deactivateMode()
else if (linksMatched.length == 1)
@activateLink(linksMatched[0], delay)
else
@@ -303,7 +295,7 @@ LinkHints =
clickEl = matchedLink.clickableItem
if (DomUtils.isSelectable(clickEl))
DomUtils.simulateSelect(clickEl)
- @handlerMode.exit delay, -> LinkHints.delayMode = false
+ @deactivateMode(delay, -> LinkHints.delayMode = false)
else
# TODO figure out which other input elements should not receive focus
if (clickEl.nodeName.toLowerCase() == "input" && clickEl.type != "button")
@@ -311,11 +303,11 @@ LinkHints =
DomUtils.flashRect(matchedLink.rect)
@linkActivator(clickEl)
if @mode is OPEN_WITH_QUEUE
- @handlerMode.exit delay, ->
+ @deactivateMode delay, ->
LinkHints.delayMode = false
LinkHints.activateModeWithQueue()
else
- @handlerMode.exit delay, -> LinkHints.delayMode = false
+ @deactivateMode(delay, -> LinkHints.delayMode = false)
#
# Shows the marker, highlighting matchingCharCount characters.
@@ -342,6 +334,7 @@ LinkHints =
if (LinkHints.hintMarkerContainingDiv)
DomUtils.removeElement LinkHints.hintMarkerContainingDiv
LinkHints.hintMarkerContainingDiv = null
+ @hintMode.exit()
HUD.hide()
@isActive = false