diff options
| author | Stephen Blott | 2015-05-08 15:39:13 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-08 15:39:13 +0100 | 
| commit | 5e6fa4ccfc103750b84df02a35f42a6acef78fa1 (patch) | |
| tree | 2aed4e810950f9bf5127ba691e41850e1091325a /pages/vomnibar.coffee | |
| parent | 9887c8d763bf7b58e459a48f34531f6877ffebf4 (diff) | |
| download | vimium-5e6fa4ccfc103750b84df02a35f42a6acef78fa1.tar.bz2 | |
Search completion; suppress custom search keyword.
Diffstat (limited to 'pages/vomnibar.coffee')
| -rw-r--r-- | pages/vomnibar.coffee | 19 | 
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?()  | 
