aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/completion.coffee4
-rw-r--r--pages/vomnibar.coffee24
2 files changed, 25 insertions, 3 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index d8cf1667..c13d0625 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -330,7 +330,9 @@ class SearchEngineCompleter
completions =
for suggestion in suggestions
url = Utils.createSearchUrl suggestion.split /\s+/
- new Suggestion queryTerms, "search", url, suggestion, @computeRelevancy, characterCount
+ suggestion = new Suggestion queryTerms, "search", url, suggestion, @computeRelevancy, characterCount
+ suggestion.insertText = true
+ suggestion
onComplete completions
computeRelevancy: (suggestion) ->
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index ce0eb61c..45a3a7db 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -93,6 +93,22 @@ class VomnibarUI
for i in [0...@completionList.children.length]
@completionList.children[i].className = (if i == @selection then "vomnibarSelected" else "")
+ # For suggestions from search-engine completion, we copy the suggested text into the input when selected,
+ # and revert when not.
+ if 0 <= @selection
+ suggestion = @completions[@selection]
+ if suggestion.insertText
+ @previousText ?= @input.value
+ @input.value = suggestion.title
+ else
+ if @previousText?
+ @input.value = @previousText
+ @previousText = null
+ else
+ if @previousText?
+ @input.value = @previousText
+ @previousText = null
+
#
# Returns the user's action ("up", "down", "enter", "dismiss" or null) based on their keypress.
# We support the arrow keys and other shortcuts for moving, so this method hides that complexity.
@@ -141,9 +157,9 @@ class VomnibarUI
handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
url: query
else
+ completion = @completions[@selection]
@update true, =>
# Shift+Enter will open the result in a new tab instead of the current tab.
- completion = @completions[@selection]
@hide -> completion.performAction openInNewTab
# It seems like we have to manually suppress the event here and still return true.
@@ -168,8 +184,12 @@ class VomnibarUI
update: (updateSynchronously, callback) =>
if (updateSynchronously)
+ # The use entered something. Don't reset any previous text.
+ if @previousText?
+ @previousText = null
+ @selection = -1
# cancel scheduled update
- if (@updateTimer != null)
+ if @updateTimer?
window.clearTimeout(@updateTimer)
@updateTimer = null
@updateCompletions(callback)