diff options
| -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. # |
