diff options
| author | Stephen Blott | 2015-05-12 12:13:21 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-12 12:13:21 +0100 | 
| commit | 51f97efb0b2839b3d9cbc0dd61b8e2e12c9b0b9b (patch) | |
| tree | 7a3b135966cac4168c32f5cd05e05c3adcd0b6cf | |
| parent | c2c744b1962af4413722ce468fe3e555fff8496e (diff) | |
| download | vimium-51f97efb0b2839b3d9cbc0dd61b8e2e12c9b0b9b.tar.bz2 | |
Tweak vomnibar for custom search.
This applies only to custom searches for which we have a completion engine.
Status quo: Exclusively offer suggestions generated by this completer.
This PR: Also include other suggestions (e.g. history) if their URL and
query match this custom search engine.
| -rw-r--r-- | background_scripts/completion.coffee | 35 | 
1 files changed, 19 insertions, 16 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 85829c75..28650711 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -362,17 +362,13 @@ class SearchEngineCompleter      CompletionSearch.cancel()    # This looks up the custom search engine and, if one is found, notes it and removes its keyword from the -  # query terms.  It also sets request.completers to indicate that only this completer should run (but only if -  # it finds a completion engine). +  # query terms.    triageRequest: (request) ->      @searchEngines.use (engines) =>        { queryTerms, query } = request        keyword = queryTerms[0]        # Note. For a keyword "w", we match "w search terms" and "w ", but not "w" on its own.        if keyword and engines[keyword] and (1 < queryTerms.length or /\s$/.test query) -        # This is a query for a custom search engine.  If we have a completion engine, then we *only* want -        # suggestions from SearchEngineCompleter. -        request.completers = [ this ] if CompletionSearch.haveCompletionEngine engines[keyword].searchUrl          extend request,            queryTerms: queryTerms[1..]            keyword: keyword @@ -395,6 +391,7 @@ class SearchEngineCompleter            keyword: keyword            searchUrl: url            description: description +          searchUrlPrefix: url.split("%s")[0]        callback engines @@ -441,11 +438,22 @@ class SearchEngineCompleter      # This distinguishes two very different kinds of vomnibar baviours, the newer bahviour (true) and the      # legacy behavior (false).  We retain the latter for the default search engine, and for custom search -    # engines for which we do not have a completion engine.  By "exclusive vomnibar", we mean suggestions -    # from other completers are suppressed (so the vomnibar "exclusively" uses suggestions from this search -    # engine). +    # engines for which we do not have a completion engine.  By "exclusive vomnibar", we mean that +    # this completer exclusively controls which suggestions may or may not be included, including filtering +    # out suggestions from other completers.      useExclusiveVomnibar = custom and haveCompletionEngine -    filter = if useExclusiveVomnibar then (suggestion) -> suggestion.type == description else null + +    filter = null +    if useExclusiveVomnibar +      # We accept suggestions from this completer; and we also accept suggestions from other completers, but +      # only if their URL matches this search engine and the query (ie. they could have been generated by this +      # search engine previously). +      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..])      # For custom search engines, we add a single, top-ranked entry for the unmodified query.  This      # suggestion always appears at the top of the list. @@ -514,13 +522,8 @@ class MultiCompleter      return @mostRecentQuery = arguments if @filterInProgress      # Provide each completer with an opportunity to see (and possibly alter) the request before it is -    # launched.  Each completer is also provided with a list of all of the completers we're using -    # (request.completers), and may change that list to override the default (for example, the -    # search-engine completer does this if it wants to be the *only* completer). -    request.completers = @completers +    # launched.      completer.triageRequest? request for completer in @completers -    completers = request.completers -    delete request.completers      RegexpCache.clear()      { queryTerms } = request @@ -529,7 +532,7 @@ class MultiCompleter      [ suggestions, continuations, filters ] = [ [], [], [] ]      # Run each of the completers (asynchronously). -    jobs = new JobRunner completers.map (completer) -> +    jobs = new JobRunner @completers.map (completer) ->        (callback) ->          completer.filter request, (newSuggestions = [], { continuation, filter } = {}) ->            suggestions.push newSuggestions...  | 
