aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee6
-rw-r--r--background_scripts/main.coffee10
-rw-r--r--background_scripts/search_engines.coffee8
3 files changed, 19 insertions, 5 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 33d8a563..92936098 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -331,6 +331,9 @@ class TabCompleter
class SearchEngineCompleter
searchEngines: {}
+ userIsTyping: ->
+ SearchEngines.userIsTyping()
+
filter: (queryTerms, onComplete) ->
{ keyword: keyword, url: url, description: description } = @getSearchEngineMatches queryTerms
custom = url?
@@ -443,6 +446,9 @@ class MultiCompleter
refresh: ->
completer.refresh?() for completer in @completers
+ userIsTyping: ->
+ completer.userIsTyping?() for completer in @completers
+
filter: (queryTerms, onComplete) ->
# Allow only one query to run at a time.
if @filterInProgress
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 45619023..44644769 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -221,9 +221,13 @@ refreshCompleter = (request) -> completers[request.name].refresh()
whitespaceRegexp = /\s+/
filterCompleter = (args, port) ->
- 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
+ if args.name? and args.userIsTyping
+ completers[args.name].userIsTyping?()
+
+ 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
chrome.tabs.onSelectionChanged.addListener (tabId, selectionInfo) ->
if (selectionChangedHandlers.length > 0)
diff --git a/background_scripts/search_engines.coffee b/background_scripts/search_engines.coffee
index 608115f3..74e752e3 100644
--- a/background_scripts/search_engines.coffee
+++ b/background_scripts/search_engines.coffee
@@ -13,7 +13,7 @@
# 3. "parse" - This takes a successful XMLHttpRequest object (the request has completed successfully), and
# returns a list of suggestions (a list of strings).
#
-# The main (only) completion entry point is SearchEngines.complete(). This implements all lookup and caching
+# The main completion entry point is SearchEngines.complete(). This implements all lookup and caching
# logic. It is possible to add new completion engines without changing the SearchEngines infrastructure
# itself.
@@ -197,7 +197,7 @@ SearchEngines =
# We pause in case the user is still typing.
Utils.setTimeout 200, handler = @mostRecentHandler = =>
- if handler != @mostRecentHandler # Bail if another completion has begun.
+ if handler != @mostRecentHandler # Bail if another completion has begun, or the user is typing.
console.log "bail", completionCacheKey if @debug
return callback []
# Don't allow duplicate identical active requests. This can happen, for example, when the user enters or
@@ -211,5 +211,9 @@ SearchEngines =
console.log "callbacks", queue.length, completionCacheKey if @debug and 0 < queue.length
callback suggestions for callback in queue
+ userIsTyping: ->
+ console.log "reset (typing)" if @debug and @mostRecentHandler?
+ @mostRecentHandler = null
+
root = exports ? window
root.SearchEngines = SearchEngines