aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/completion.coffee4
-rw-r--r--pages/vomnibar.coffee19
2 files changed, 21 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index b9efb034..9d249198 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -382,6 +382,8 @@ class SearchEngineCompleter
autoSelect: true
# Always reset the selection to this suggestion on query change. The UX is weird otherwise.
forceAutoSelect: true
+ # Suppress the "w" from "w query terms" in the vomnibar input.
+ suppressLeadingQueryTerm: true
onComplete suggestions,
exclusive: if custom and CompletionEngines.haveCompletionEngine searchUrl then description else null
@@ -418,7 +420,7 @@ class SearchEngineCompleter
title: suggestion
relevancy: relavancy *= 0.9
highlightTerms: false
- insertText: if custom then "#{keyword} #{suggestion}" else suggestion
+ insertText: suggestion
# We keep at least three suggestions (if possible) and at most six. We keep more than three only if
# there are enough slots. The idea is that these suggestions shouldn't wholly displace suggestions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index f980f3f4..1188c411 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -68,6 +68,7 @@ class VomnibarUI
@updateTimer = null
@previousAutoSelect = null
@previousInputValue = null
+ @suppressedLeadingQueryTerm = null
@selection = @initialSelectionValue
updateSelection: ->
@@ -80,6 +81,19 @@ class VomnibarUI
else
@previousAutoSelect = null
+ # For custom search engines, we suppress the leading term (e.g. the "w" of "w query terms") within the
+ # vomnibar input.
+ if @suppressedLeadingQueryTerm?
+ # If we have a suppressed term and the input is empty, then reinstate it.
+ if @input.value.trim().split(/\s+/).join("").length == 0
+ @input.value = @getInputValue()
+ @suppressedLeadingQueryTerm = null
+ else if @completions[0]?.suppressLeadingQueryTerm
+ # We've been asked to suppress the leading query term, and it's not already suppressed. So suppress it.
+ queryTerms = @input.value.trim().split /\s+/
+ @suppressedLeadingQueryTerm = queryTerms[0]
+ @input.value = queryTerms[1..].join " "
+
# For suggestions from search-engine completion, we copy the suggested text into the input when selected,
# and revert when not. This allows the user to select a suggestion and then continue typing.
if 0 <= @selection and @completions[@selection].insertText?
@@ -149,8 +163,11 @@ class VomnibarUI
event.preventDefault()
true
+ getInputValue: ->
+ (if @suppressedLeadingQueryTerm? then @suppressedLeadingQueryTerm + " " else "") + @input.value
+
updateCompletions: (callback = null) ->
- @completer.filter @input.value, (@completions) =>
+ @completer.filter @getInputValue(), (@completions) =>
@populateUiWithCompletions @completions
callback?()