aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2016-01-29 16:12:51 +0000
committerStephen Blott2016-01-31 11:33:29 +0000
commit4a65357111554d607d89a3ad8698342177887fed (patch)
tree345ae9b1fc589420e588660800875ac3efa4eb19 /content_scripts
parentc2e55bdcbaabb6dccf76feafed023960c60b1854 (diff)
downloadvimium-4a65357111554d607d89a3ad8698342177887fed.tar.bz2
Better scoring for filtered hints.
It is often the case that an encosing element (parent) and a child are both clickable, and both contain the same text. In this case, it is usually better to pick the child. So, here, we dampen down the score of elements with longer texts.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/link_hints.coffee13
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.