diff options
| author | Stephen Blott | 2015-05-28 15:56:18 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-28 15:56:21 +0100 | 
| commit | 45157bc460494503ca2b90caa762e72d224a1ef3 (patch) | |
| tree | f912e1536911fc8a783d31fb396d078144ec9d51 | |
| parent | a975ce087c4beac442e5cfaeb7fb0510e54c82a4 (diff) | |
| download | vimium-45157bc460494503ca2b90caa762e72d224a1ef3.tar.bz2 | |
Custom-only: fix long-standing race condition.
In omni mode, the vomnibar suggestions are updated asynchronously.
Therefore, the contents of the primary custom search-engine suggestion
may be behind the actual contents of the comnibar input.  So, we
reconstruct the custom search-engine query on "enter".
(This fixes a long-standing race condition.)
| -rw-r--r-- | background_scripts/completion.coffee | 1 | ||||
| -rw-r--r-- | pages/vomnibar.coffee | 12 | 
2 files changed, 11 insertions, 2 deletions
| diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index d8b946a1..60e5f1df 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -505,6 +505,7 @@ class SearchEngineCompleter        autoSelect: true        highlightTerms: false        isSearchSuggestion: true +      isPrimarySuggestion: true      return onComplete [ primarySuggestion ], { filter } if queryTerms.length == 0 diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 4bf971e4..82de067f 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -138,15 +138,23 @@ class VomnibarUI        @selection = @completions.length - 1 if @selection < @initialSelectionValue        @updateSelection()      else if (action == "enter") -      if @selection == -1 +      isCustomSearchPrimarySuggestion = @completions[@selection]?.isPrimarySuggestion and @lastReponse.engine?.searchUrl? +      if @selection == -1 or isCustomSearchPrimarySuggestion          query = @input.value.trim()          # <Enter> on an empty query is a no-op.          return unless 0 < query.length +        # First case (@selection == -1).          # If the user types something and hits enter without selecting a completion from the list, then:          #   - If a search URL has been provided, then use it.  This is custom search engine request.          #   - Otherwise, send the query to the background page, which will open it as a URL or create a          #     default search, as appropriate. -        query = Utils.createSearchUrl query, @lastReponse.searchUrl if @lastReponse.searchUrl? +        # +        # Second case (isCustomSearchPrimarySuggestion). +        # Alternatively, the selected completion could be the primary selection for a custom search engine. +        # Because the the suggestions are updated asynchronously in omni mode, the user may have typed more +        # text than that which is included in the URL associated with the primary suggestion.  Therefore, to +        # avoid a race condition, we construct the query from the actual contents of the input (query). +        query = Utils.createSearchUrl query, @lastReponse.engine.searchUrl if isCustomSearchPrimarySuggestion          @hide ->            chrome.runtime.sendMessage              handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab" | 
