diff options
| author | Stephen Blott | 2016-01-31 11:40:30 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-01-31 11:40:30 +0000 |
| commit | 1f8abb98a3750a00ee16aac34f81de27413f1816 (patch) | |
| tree | 345ae9b1fc589420e588660800875ac3efa4eb19 | |
| parent | c2e55bdcbaabb6dccf76feafed023960c60b1854 (diff) | |
| parent | 4a65357111554d607d89a3ad8698342177887fed (diff) | |
| download | vimium-1f8abb98a3750a00ee16aac34f81de27413f1816.tar.bz2 | |
Merge pull request #1960 from smblott-github/link-hints-better-score-shorter-texts
Better scoring for filtered hints.
| -rw-r--r-- | content_scripts/link_hints.coffee | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 84c9f7f9..54476935 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -594,7 +594,8 @@ class FilterHints scoreLinkHint: (linkSearchString) -> searchWords = linkSearchString.trim().split /\s+/ (linkMarker) -> - linkWords = linkMarker.linkWords ?= linkMarker.linkText.trim().toLowerCase().split /\s+/ + text = linkMarker.linkText.trim() + linkWords = linkMarker.linkWords ?= text.toLowerCase().split /\s+/ searchWordScores = for searchWord in searchWords @@ -610,8 +611,14 @@ class FilterHints 0 Math.max linkWordScores... - addFunc = (a,b) -> a + b - if 0 in searchWordScores then 0 else searchWordScores.reduce addFunc, 0 + if 0 in searchWordScores + 0 + else + addFunc = (a,b) -> a + b + score = searchWordScores.reduce addFunc, 0 + # Prefer matches in shorter texts. To keep things balanced for links without any text, we just weight + # them as if their length was 50. + score / Math.log(text.length || 50) # # Make each hint character a span, so that we can highlight the typed characters as you type them. |
