aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/completion_engines.coffee
diff options
context:
space:
mode:
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()