aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-05-13 08:46:08 +0100
committerStephen Blott2015-05-13 09:50:45 +0100
commit80f411ef238be2af24819e69de3e7d39760ecc1c (patch)
tree545a80f0477e46d231021a98285436af2f9c2ec8 /background_scripts
parent895d6c47f71b1f5cf4eb506573b742a6748fb299 (diff)
downloadvimium-80f411ef238be2af24819e69de3e7d39760ecc1c.tar.bz2
Search completion; rework handling when no selection.
This makes the behaviour consistent between custom and non-custom searches when there is no selection in the vomnibar (omni-mode only). Approach: - When there is no selection in the vomnibar, we *always* send the query to to background completer (that is, both for default searches and for custom searches) and ask the completer to provide only the primary suggestion. The primary suggestion is just what you get if you append the query terms to the search URL (default or custom). We then immediately open the first response. The round trip for default searches isn't strictly necessary. However, this uniform approach disentangles some nasty logic in the vomnibar when we're trying to handle several cases (default or custom search, with or without prompted text, with or without any suggestions at all). The extra round trip simplifies the logic to such a great extend that it's worth it.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee62
1 files changed, 30 insertions, 32 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 02030444..bf88f10e 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -402,7 +402,7 @@ class SearchEngineCompleter
handler: "keywords"
keywords: key for own key of engines
- filter: ({ queryTerms, query, engine }, onComplete) ->
+ filter: ({ queryTerms, query, engine, fetchOnlyThePrimarySuggestion }, onComplete) ->
[ primarySuggestion, removePrimarySuggestion ] = [ null, false ]
{ custom, searchUrl, description } =
@@ -455,29 +455,27 @@ class SearchEngineCompleter
# And the URL suffix (which must contain the query part) matches the current query.
RankingUtils.matches queryTerms, suggestion.url[engine.searchUrlPrefix.length..])
- # If we've delivered suggestions from a completion engine, then we can strip out the primary
- # suggestion.
- if removePrimarySuggestion
- suggestions = suggestions.filter (suggestion) -> suggestion != primarySuggestion
-
- suggestions
-
- # For custom search engines, we add a single, top-ranked entry for the unmodified query. This
- # suggestion appears at the top of the list. This is the primary suggestion.
- if custom
- primarySuggestion = new Suggestion
- queryTerms: queryTerms
- type: description
- url: Utils.createSearchUrl queryTerms, searchUrl
- title: queryTerms.join " "
- relevancy: 1
- insertText: query
- # We suppress the leading keyword, for example "w something" becomes "something" in the vomnibar.
- suppressLeadingKeyword: true
- # Toggles for the legacy behaviour.
- autoSelect: not useExclusiveVomnibar
- forceAutoSelect: not useExclusiveVomnibar
- highlightTerms: not useExclusiveVomnibar
+ if fetchOnlyThePrimarySuggestion
+ suggestions.filter (suggestion) -> suggestion == primarySuggestion
+ else if removePrimarySuggestion
+ suggestions.filter (suggestion) -> suggestion != primarySuggestion
+ else
+ suggestions
+
+ primarySuggestion = new Suggestion
+ queryTerms: queryTerms
+ type: description
+ url: Utils.createSearchUrl queryTerms, searchUrl
+ title: queryTerms.join " "
+ relevancy: relevancy
+ insertText: if useExclusiveVomnibar then query else null
+ # We suppress the leading keyword for custom search engines; for example, "w query terms" becomes just
+ # "query terms" in the vomnibar.
+ suppressLeadingKeyword: custom
+ # Toggles for the legacy behaviour.
+ autoSelect: not useExclusiveVomnibar
+ forceAutoSelect: not useExclusiveVomnibar
+ highlightTerms: not useExclusiveVomnibar
mkSuggestion = (suggestion) ->
new Suggestion
@@ -492,27 +490,27 @@ class SearchEngineCompleter
deliverCompletions = (onComplete, completions, args...) ->
# Make the first suggestion float to the top of the vomnibar (except if we would be competing with the
- # domain completer).
+ # domain completer, which also assigns a relevancy of 1).
if 0 < completions.length
- if custom or (1 < queryTerms.length or /\S\s/.test query)
- completions[0].relevancy = 1
+ completions[0].relevancy = 1 if custom or (1 < queryTerms.length or /\S\s/.test query)
onComplete completions, args...
# If we have cached suggestions, then we can bundle them immediately (otherwise we'll have to fetch them
# asynchronously).
cachedSuggestions = null
- cachedSuggestions = CompletionSearch.complete searchUrl, queryTerms if haveCompletionEngine
+ cachedSuggestions = CompletionSearch.complete searchUrl, queryTerms if haveCompletionEngine and not fetchOnlyThePrimarySuggestion
suggestions =
- if haveCompletionEngine and cachedSuggestions? and 0 < cachedSuggestions.length
+ if haveCompletionEngine and cachedSuggestions? and 0 < cachedSuggestions.length and not fetchOnlyThePrimarySuggestion
cachedSuggestions.map mkSuggestion
- else if custom
+ else if custom or fetchOnlyThePrimarySuggestion
[ primarySuggestion ]
else
[]
- if queryTerms.length == 0 or cachedSuggestions? or not haveCompletionEngine
- # There is no prospect of adding further completions.
+ if queryTerms.length == 0 or cachedSuggestions? or not haveCompletionEngine or fetchOnlyThePrimarySuggestion
+ # There is no prospect of adding further completions, or further completions will not be used (eg.
+ # because the vomnibar is closing and we've been asked for the primary suggestion only).
deliverCompletions onComplete, suggestions, { filter, continuation: null }
else
# Post initial suggestions, then deliver further completions asynchronously, as a continuation.