aboutsummaryrefslogtreecommitdiffstats
path: root/pages/vomnibar.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'pages/vomnibar.coffee')
-rw-r--r--pages/vomnibar.coffee19
1 files changed, 18 insertions, 1 deletions
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?()