diff options
| author | Stephen Blott | 2015-05-18 15:31:17 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-18 15:31:21 +0100 | 
| commit | 6026e7bc2dd99e947d06ba2dce29e3d3eac47a91 (patch) | |
| tree | 09332ba9b59bebada62bd3e005b44c3e933211ec /background_scripts | |
| parent | 3646b8c999a9e4b864e8c529f84b64a3c2c74ff0 (diff) | |
| download | vimium-6026e7bc2dd99e947d06ba2dce29e3d3eac47a91.tar.bz2 | |
Search completion; filter out the default search.
See example in diff.
Do not offer a suggestion if it is what the user would get anyway if
they just hit <Enter>.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion.coffee | 30 | 
1 files changed, 18 insertions, 12 deletions
| diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 3e7cfe06..1ed92034 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -470,18 +470,24 @@ class SearchEngineCompleter      # This filter is applied to all of the suggestions from all of the completers, after they have been      # aggregated by the MultiCompleter.      filter = (suggestions) -> -      return suggestions unless custom and haveCompletionEngine - -      # We only accept suggestions: -      #   - from this completer, or -      #   - from other completers, but then only if their URL matches this search engine and matches this -      #     query (that is only if their URL could have been generated by this search engine). -      suggestions.filter (suggestion) -> -        suggestion.type == description or -          # This is a suggestion for the same search engine. -          (suggestion.url.startsWith(engine.searchUrlPrefix) and -            # And the URL suffix (which must contain the query part) matches the current query. -            RankingUtils.matches queryTerms, suggestion.url[engine.searchUrlPrefix.length..]) +      if custom and haveCompletionEngine +        # We only accept suggestions: +        #   - from this completer, or +        #   - from other completers, but then only if their URL matches this search engine and matches this +        #     query (that is only if their URL could have been generated by this search engine). +        suggestions.filter (suggestion) -> +          suggestion.type == description or +            # This is a suggestion for the same search engine. +            (suggestion.url.startsWith(engine.searchUrlPrefix) and +              # And the URL suffix (which must contain the query part) matches the current query. +              RankingUtils.matches queryTerms, suggestion.url[engine.searchUrlPrefix.length..]) + +      else if not custom +        # Filter out any suggestion which is just what the user would get if they hit <Enter> anyway.  For +        # example, don't offer "https://www.google.com/search?q=vimium" if the query is "vimium". +        defaultUrl = Utils.createSearchUrl queryTerms, searchUrl +        defaultQuery = queryTerms.join " " +        suggestions.filter (suggestion) -> Utils.extractQuery(searchUrl, suggestion.url) != defaultQuery      # If a previous suggestion still matches the query, then we keep it (even if the completion engine may not      # return it for the current query).  This allows the user to pick suggestions by typing fragments of their | 
