aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-05-05 14:47:02 +0100
committerStephen Blott2015-05-05 14:47:06 +0100
commit7c855af38cfdf32a05b90b2da4711720ebac8865 (patch)
tree1ce262948ac2aa6992ac8f48b7bad82bb1748ea1
parente21896e2af7f28eb17b5b98a32cfce32fe171d3a (diff)
downloadvimium-7c855af38cfdf32a05b90b2da4711720ebac8865.tar.bz2
Search completion; user is typing.
Add plumbing to allow the front end to directly inform completers when the user is typing.
-rw-r--r--background_scripts/completion.coffee6
-rw-r--r--background_scripts/main.coffee10
-rw-r--r--background_scripts/search_engines.coffee8
-rw-r--r--pages/vomnibar.coffee4
4 files changed, 23 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
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 58513dc2..8a070df6 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -178,6 +178,7 @@ class VomnibarUI
@updateSelection()
updateOnInput: =>
+ @completer.userIsTyping()
# If the user types, then don't reset any previous text, and re-enable auto-select.
if @previousInputValue?
@previousInputValue = null
@@ -253,6 +254,9 @@ class BackgroundCompleter
@filterPort.postMessage id: id, name: @name, query: query
+ userIsTyping: ->
+ @filterPort.postMessage name: @name, userIsTyping: true
+
extend BackgroundCompleter,
#
# These are the actions we can perform when the user selects a result in the Vomnibox.