diff options
| -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 | 
