aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/completion.coffee4
-rw-r--r--background_scripts/main.coffee4
-rw-r--r--pages/vomnibar.coffee44
3 files changed, 25 insertions, 27 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 729e86ab..c91825b5 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -478,12 +478,12 @@ class MultiCompleter
# (ie. a SearchEngineCompleter). This prevents hiding the vomnibar briefly before showing it
# again, which looks ugly.
unless shouldRunContinuation and suggestions.length == 0
- onComplete @prepareSuggestions(queryTerms, suggestions), keepAlive: shouldRunContinuation
+ onComplete @prepareSuggestions queryTerms, suggestions
# Allow subsequent queries to begin.
@filterInProgress = false
if shouldRunContinuation
continuation suggestions, (newSuggestions) =>
- onComplete @prepareSuggestions queryTerms, suggestions.concat(newSuggestions)
+ onComplete @prepareSuggestions queryTerms, suggestions.concat newSuggestions
else
@filter @mostRecentQuery.queryTerms, @mostRecentQuery.onComplete if @mostRecentQuery
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 44644769..09a6b89f 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -226,8 +226,8 @@ filterCompleter = (args, port) ->
if args.id? and args.name? and args.query?
queryTerms = if (args.query == "") then [] else args.query.split(whitespaceRegexp)
- completers[args.name].filter queryTerms, (results, extra = {}) ->
- port.postMessage extend extra, id: args.id, results: results
+ completers[args.name].filter queryTerms, (results) ->
+ port.postMessage id: args.id, results: results
chrome.tabs.onSelectionChanged.addListener (tabId, selectionInfo) ->
if (selectionChangedHandlers.length > 0)
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 8a070df6..d9a86a3f 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -223,37 +223,35 @@ class VomnibarUI
# Sends filter and refresh requests to a Vomnibox completer on the background page.
#
class BackgroundCompleter
- # We increment this counter on each message sent, and ignore responses which arrive too late.
- @messageId: 0
-
# - name: The background page completer that you want to interface with. Either "omni", "tabs", or
# "bookmarks". */
constructor: (@name) ->
+ @messageId = null
@filterPort = chrome.runtime.connect name: "filterCompleter"
+ @filterPort.onMessage.addListener handler = @messageHandler
+
+ messageHandler: (msg) =>
+ # We ignore messages which arrive too late.
+ if msg.id == @messageId
+ # The result objects coming from the background page will be of the form:
+ # { html: "", type: "", url: "" }
+ # type will be one of [tab, bookmark, history, domain].
+ results = msg.results.map (result) ->
+ functionToCall = if result.type == "tab"
+ BackgroundCompleter.completionActions.switchToTab.curry result.tabId
+ else
+ BackgroundCompleter.completionActions.navigateToUrl.curry result.url
+ result.performAction = functionToCall
+ result
+ @mostRecentCallback results
+
+ filter: (query, @mostRecentCallback) ->
+ @messageId = Utils.createUniqueId()
+ @filterPort.postMessage id: @messageId, name: @name, query: query
refresh: ->
chrome.runtime.sendMessage handler: "refreshCompleter", name: @name
- filter: (query, callback) ->
- id = BackgroundCompleter.messageId += 1
- @filterPort.onMessage.addListener handler = (msg) =>
- if msg.id == id
- @filterPort.onMessage.removeListener handler unless msg.keepAlive and id == BackgroundCompleter.messageId
- if id == BackgroundCompleter.messageId
- # The result objects coming from the background page will be of the form:
- # { html: "", type: "", url: "" }
- # type will be one of [tab, bookmark, history, domain].
- results = msg.results.map (result) ->
- functionToCall = if (result.type == "tab")
- BackgroundCompleter.completionActions.switchToTab.curry(result.tabId)
- else
- BackgroundCompleter.completionActions.navigateToUrl.curry(result.url)
- result.performAction = functionToCall
- result
- callback(results)
-
- @filterPort.postMessage id: id, name: @name, query: query
-
userIsTyping: ->
@filterPort.postMessage name: @name, userIsTyping: true