diff options
| author | Stephen Blott | 2015-05-12 12:23:46 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-05-12 12:23:46 +0100 |
| commit | 95d3aa2830b4a64c0c30ab682d63f0623ea35a3f (patch) | |
| tree | 032177a659f58b35d943d0f2500447b1b3db379f | |
| parent | 26f91fea40f11c116497ce20c1fe53f3956a922f (diff) | |
| parent | 51f97efb0b2839b3d9cbc0dd61b8e2e12c9b0b9b (diff) | |
| download | vimium-95d3aa2830b4a64c0c30ab682d63f0623ea35a3f.tar.bz2 | |
Merge pull request #1655 from smblott-github/completion-filters
Tweak vomnibar for custom search.
| -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... |
