diff options
| author | Stephen Blott | 2016-04-08 09:42:22 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-04-08 09:45:22 +0100 | 
| commit | 1a71dc6c8f323cef31eb006a8a6299b4dfe71332 (patch) | |
| tree | 0fd8812199921216658e58fc0b6689a354c618e8 | |
| parent | bee5ee8416be776f379beb1bf772665a19cd3fa4 (diff) | |
| download | vimium-1a71dc6c8f323cef31eb006a8a6299b4dfe71332.tar.bz2 | |
Filtered hints; ignore unmatched text.
When the user is typing a link's text, any mistyped character exits link
hints mode.  This makes little sense.  In practice, this usually happens
because the user mis-typed something.
Here, we ignore typed characters which do not match any hints.
(Also, add a test for this.)
| -rw-r--r-- | content_scripts/link_hints.coffee | 20 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 12 | 
2 files changed, 25 insertions, 7 deletions
| diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 56cea78d..56edf22f 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -465,15 +465,21 @@ class FilterHints      linkSearchString = @linkTextKeystrokeQueue.join("").trim().toLowerCase()      do (scoreFunction = @scoreLinkHint linkSearchString) ->        linkMarker.score = scoreFunction linkMarker for linkMarker in hintMarkers -    hintMarkers = hintMarkers[..].sort (a,b) -> +    matchingHintMarkers = hintMarkers[..].sort (a,b) ->        if b.score == a.score then b.stableSortCount - a.stableSortCount else b.score - a.score -    linkHintNumber = 1 -    for linkMarker in hintMarkers -      continue unless 0 < linkMarker.score -      linkMarker.hintString = @generateHintString linkHintNumber++ -      @renderMarker linkMarker -      linkMarker +    matchingHintMarkers = (linkMarker for linkMarker in matchingHintMarkers when 0 < linkMarker.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. +      @linkTextKeystrokeQueue.pop() +      @filterLinkHints hintMarkers +    else +      linkHintNumber = 1 +      for linkMarker in matchingHintMarkers +        linkMarker.hintString = @generateHintString linkHintNumber++ +        @renderMarker linkMarker +        linkMarker    # 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. diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index 3977d046..96d95902 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -282,6 +282,18 @@ context "Filtered link hints",        sendKeyboardEvent "A"        assert.equal "1", hintMarkers[3].hintString +    # This test is the same as above, but with an extra non-matching character. +    should "narrow the hints and ignore typing mistakes", -> +      hintMarkers = getHintMarkers() +      sendKeyboardEvent "T" +      sendKeyboardEvent "R" +      sendKeyboardEvent "X" +      assert.equal "none", hintMarkers[0].style.display +      assert.equal "3", hintMarkers[1].hintString +      assert.equal "", hintMarkers[1].style.display +      sendKeyboardEvent "A" +      assert.equal "1", hintMarkers[3].hintString +    context "Image hints",      setup -> | 
