aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/completion.coffee3
-rw-r--r--pages/vomnibar.coffee14
2 files changed, 8 insertions, 9 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index d6402019..177892fb 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -21,6 +21,8 @@ class Suggestion
# - extraRelevancyData: data (like the History item itself) which may be used by the relevancy function.
constructor: (@queryTerms, @type, @url, @title, @computeRelevancyFunction, @extraRelevancyData) ->
@title ||= ""
+ # When @autoSelect is truthy, the suggestion is automatically pre-selected in the vomnibar.
+ @autoSelect = false
computeRelevancy: -> @relevancy = @computeRelevancyFunction(this)
@@ -335,6 +337,7 @@ class SearchEngineCompleter
type = "search"
query = queryTerms[0] + ": " + queryTerms[1..].join(" ")
suggestion = new Suggestion(queryTerms, type, url, query, @computeRelevancy)
+ suggestion.autoSelect = true
suggestions.push(suggestion)
onComplete(suggestions)
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 0ade7f0e..18a72a37 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -69,18 +69,14 @@ class VomnibarUI
@selection = @initialSelectionValue
updateSelection: ->
- # We have taken the option to add some global state here (previousCompletionType) to tell if a search
- # item has just appeared or disappeared, if that happens we either set the initialSelectionValue to 0 or 1
- # I feel that this approach is cleaner than bubbling the state up from the suggestion level
- # so we just inspect it afterwards
+ # We retain global state here (previousAutoSelect) to tell if a search item (for which autoSelect is set)
+ # has just appeared or disappeared. If that happens, we set @selection to 0 or -1.
if @completions[0]
- if @previousCompletionType != "search" && @completions[0].type == "search"
- @selection = 0
- else if @previousCompletionType == "search" && @completions[0].type != "search"
- @selection = -1
+ @selection = 0 if @completions[0].autoSelect and not @previousAutoSelect
+ @selection = -1 if @previousAutoSelect and not @completions[0].autoSelect
+ @previousAutoSelect = @completions[0].autoSelect
for i in [0...@completionList.children.length]
@completionList.children[i].className = (if i == @selection then "vomnibarSelected" else "")
- @previousCompletionType = @completions[0].type if @completions[0]
#
# Returns the user's action ("up", "down", "enter", "dismiss" or null) based on their keypress.