From 6a322975f561764d1a4ecb8ebd32edea12909e80 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 15 May 2015 08:17:16 +0100 Subject: Give the vomnibar a (kind of) history (autoSelect). If we insert the text of hostory completions into the vomnibar input, then when the completions change, we'll pick up the arbitrary text of whatever happens to be the current selection. So we need to always reset the selection when the vomnibar updates. This eliminates the need for the previous autoSelect logic. --- background_scripts/completion.coffee | 1 - pages/vomnibar.coffee | 15 ++------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index fd0a4c51..ac234787 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -504,7 +504,6 @@ class SearchEngineCompleter title: queryTerms.join " " relevancy: 1 autoSelect: custom - forceAutoSelect: custom highlightTerms: not haveCompletionEngine mkSuggestion = (suggestion) -> diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index a20ae7f3..07eb39bb 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -67,22 +67,12 @@ class VomnibarUI @completionList.style.display = "" @input.value = "" @completions = [] - @previousAutoSelect = null @previousInputValue = null @customSearchMode = null @selection = @initialSelectionValue @keywords = [] updateSelection: -> - # 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 0 < @completions.length - @selection = 0 if @completions[0].autoSelect and not @previousAutoSelect - @selection = -1 if @previousAutoSelect and not @completions[0].autoSelect - @previousAutoSelect = @completions[0].autoSelect - 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 @lastReponse.customSearchMode and not @customSearchMode? @@ -185,20 +175,19 @@ class VomnibarUI callback: (@lastReponse) => { results } = @lastReponse @completions = results + @selection = if @completions[0]?.autoSelect then 0 else @initialSelectionValue # Update completion list with the new suggestions. @completionList.innerHTML = @completions.map((completion) -> "
  • #{completion.html}
  • ").join("") @completionList.style.display = if @completions.length > 0 then "block" else "" @selection = Math.min @completions.length - 1, Math.max @initialSelectionValue, @selection - @previousAutoSelect = null if @completions[0]?.autoSelect and @completions[0]?.forceAutoSelect @updateSelection() callback?() updateOnInput: => @completer.cancel() - # If the user types, then don't reset any previous text, and restart auto select. + # If the user types, then don't reset any previous text, and reset the selection. if @previousInputValue? @previousInputValue = null - @previousAutoSelect = null @selection = -1 @update false -- cgit v1.2.3