aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/completion_engines.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-05-10 08:59:14 +0100
committerStephen Blott2015-05-10 11:44:05 +0100
commit5191ee986615f45bfaedb389e3b34fd0a1ce9ca9 (patch)
treee0e2456c81527b35a00280ad51db5a1159381385 /background_scripts/completion_engines.coffee
parent146957c9dae54c31ce4676b5a4b60a0000c05487 (diff)
downloadvimium-5191ee986615f45bfaedb389e3b34fd0a1ce9ca9.tar.bz2
Search completion; reuse previous query.
Diffstat (limited to 'background_scripts/completion_engines.coffee')
-rw-r--r--background_scripts/completion_engines.coffee15
1 files changed, 15 insertions, 0 deletions
diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee
index 51799971..729c68b0 100644
--- a/background_scripts/completion_engines.coffee
+++ b/background_scripts/completion_engines.coffee
@@ -213,6 +213,21 @@ CompletionEngines =
return null if returnResultsOnlyFromCache
+ if @mostRecentQuery? and @mostRecentSuggestions?
+ # If the user appears to be typing a continuation of the characters in all of the most recent query,
+ # then we can re-use the results of the previous query.
+ reusePreviousSuggestions = do (query) =>
+ query = queryTerms.join(" ").toLowerCase()
+ return false unless 0 == query.indexOf @mostRecentQuery.toLowerCase()
+ previousSuggestions = @mostRecentSuggestions.map (s) -> s.toLowerCase()
+ return false unless query.length <= Utils.longestCommonPrefix previousSuggestions
+ true
+
+ if reusePreviousSuggestions
+ console.log "reuse previous query", @mostRecentQuery if @debug
+ @mostRecentQuery = queryTerms.join " "
+ return callback @completionCache.set completionCacheKey, @mostRecentSuggestions
+
fetchSuggestions = (engine, callback) =>
url = engine.getUrl queryTerms
query = queryTerms.join(" ").toLowerCase()