diff options
| author | Stephen Blott | 2015-06-08 07:35:04 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-06-08 08:11:21 +0100 |
| commit | 5662f69a71b28b107724d63f33fe9e9d8718a95e (patch) | |
| tree | 4c3ac9fe3ca7ed3138fd214e06c8b72b4ee09051 /content_scripts/link_hints.coffee | |
| parent | 3b22320266328d18f7ee606bcd6b2a2dfa5090b7 (diff) | |
| download | vimium-5662f69a71b28b107724d63f33fe9e9d8718a95e.tar.bz2 | |
Make hint filters classes.
Diffstat (limited to 'content_scripts/link_hints.coffee')
| -rw-r--r-- | content_scripts/link_hints.coffee | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 87da34d6..fbd78b1d 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -60,8 +60,8 @@ LinkHints = length = (el) -> el.element.innerHTML?.length ? 0 elements.sort (a,b) -> length(a) - length b hintMarkers = (@createMarkerFor(el) for el in elements) - @markerMatcher = if Settings.get("filterLinkHints") then filterHints else alphabetHints - @markerMatcher.fillInMarkers(hintMarkers) + @markerMatcher = new (if Settings.get "filterLinkHints" then FilterHints else AlphabetHints) + @markerMatcher.fillInMarkers hintMarkers @hintMode = new Mode name: "hint/#{mode.name}" @@ -308,6 +308,9 @@ LinkHints = @markerMatcher.pushKeyChar keyChar @updateVisibleMarkers hintMarkers + # We've handled the event, so suppress it. + DomUtils.suppressEvent event + updateVisibleMarkers: (hintMarkers, activateFirst = false) -> keyResult = @markerMatcher.getMatchingHints hintMarkers linksMatched = keyResult.linksMatched @@ -350,7 +353,6 @@ LinkHints = # showMarker: (linkMarker, matchingCharCount) -> linkMarker.style.display = "" - # TODO(philc): for j in [0...linkMarker.childNodes.length] if (j < matchingCharCount) linkMarker.childNodes[j].classList.add("matchingCharacter") @@ -363,9 +365,9 @@ LinkHints = # 'callback' is invoked (if it is provided). deactivateMode: (delay, callback) -> deactivate = => - @markerMatcher?.deactivate?() DomUtils.removeElement @hintMarkerContainingDiv if @hintMarkerContainingDiv @hintMarkerContainingDiv = null + @markerMatcher = null @isActive = false @hintMode?.exit() @hintMode = null @@ -382,11 +384,14 @@ LinkHints = deactivate() callback?() -alphabetHints = - activateOnEnter: false - hintKeystrokeQueue: [] +# Use characters for hints, and do not filter links by their text. +class AlphabetHints logXOfBase: (x, base) -> Math.log(x) / Math.log(base) + constructor: -> + @activateOnEnter = false + @hintKeystrokeQueue = [] + fillInMarkers: (hintMarkers) -> hintStrings = @hintStrings(hintMarkers.length) for marker, idx in hintMarkers @@ -442,13 +447,13 @@ alphabetHints = pushKeyChar: (keyChar) -> @hintKeystrokeQueue.push keyChar popKeyChar: -> @hintKeystrokeQueue.pop() - deactivate: -> @hintKeystrokeQueue = [] - -filterHints = - activateOnEnter: true - hintKeystrokeQueue: [] - linkTextKeystrokeQueue: [] - labelMap: {} +# Use numbers (usually) for hints, and also filter links by their text. +class FilterHints + constructor: -> + @activateOnEnter = true + @hintKeystrokeQueue = [] + @linkTextKeystrokeQueue = [] + @labelMap = {} # # Generate a map of input element => label @@ -546,11 +551,6 @@ filterHints = @renderMarker linkMarker linkMarker - deactivate: (delay, callback) -> - @hintKeystrokeQueue = [] - @linkTextKeystrokeQueue = [] - @labelMap = {} - # # Make each hint character a span, so that we can highlight the typed characters as you type them. # |
