From 5e6fa4ccfc103750b84df02a35f42a6acef78fa1 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 8 May 2015 15:39:13 +0100 Subject: Search completion; suppress custom search keyword. --- pages/vomnibar.coffee | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'pages') 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?() -- cgit v1.2.3