From 047befd24c2cbb1ab35158cc480653591843efc0 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 8 Apr 2016 13:54:28 +0100 Subject: Simplify filtered hint matching. - Reduce the number of passes over hint markers from two to one. - Filter out non-matching hints before sorting. - Do not trim the search string twice. --- content_scripts/link_hints.coffee | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index c012edba..13f28f06 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -474,13 +474,13 @@ class FilterHints # Filter link hints by search string, renumbering the hints as necessary. filterLinkHints: (hintMarkers) -> - linkSearchString = @linkTextKeystrokeQueue.join("").trim().toLowerCase() - do (scoreFunction = @scoreLinkHint linkSearchString) -> - linkMarker.score = scoreFunction linkMarker for linkMarker in hintMarkers - matchingHintMarkers = hintMarkers[..].sort (a,b) -> - if b.score == a.score then b.stableSortCount - a.stableSortCount else b.score - a.score - - matchingHintMarkers = (linkMarker for linkMarker in matchingHintMarkers when 0 < linkMarker.score) + scoreFunction = @scoreLinkHint @linkTextKeystrokeQueue.join "" + matchingHintMarkers = hintMarkers + .filter (linkMarker) -> + linkMarker.score = scoreFunction linkMarker + 0 < linkMarker.score + .sort (a, b) -> + if b.score == a.score then b.stableSortCount - a.stableSortCount else b.score - a.score if matchingHintMarkers.length == 0 and @hintKeystrokeQueue.length == 0 and 0 < @linkTextKeystrokeQueue.length # We don't accept typed text which doesn't match any hints. @@ -496,7 +496,7 @@ class FilterHints # Assign a score to a filter match (higher is better). We assign a higher score for matches at the start of # a word, and a considerably higher score still for matches which are whole words. scoreLinkHint: (linkSearchString) -> - searchWords = linkSearchString.trim().split @splitRegexp + searchWords = linkSearchString.trim().toLowerCase().split @splitRegexp (linkMarker) => text = linkMarker.linkText.trim() linkWords = linkMarker.linkWords ?= text.toLowerCase().split @splitRegexp -- cgit v1.2.3