From 4a65357111554d607d89a3ad8698342177887fed Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 Jan 2016 16:12:51 +0000 Subject: 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. --- content_scripts/link_hints.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'content_scripts') 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. -- cgit v1.2.3