diff options
| author | Stephen Blott | 2015-05-10 08:59:14 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-10 09:55:06 +0100 | 
| commit | 1a337a261a6dd6deffa836cbd949bb036e103f36 (patch) | |
| tree | 0db259e68e86f399ff6c448eb7929e4f95569eb4 /background_scripts | |
| parent | 8d51ccbb01fe2a4e7b548cc14617a05048a8d68c (diff) | |
| download | vimium-1a337a261a6dd6deffa836cbd949bb036e103f36.tar.bz2 | |
Search completion; reuse previous query.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion_engines.coffee | 19 | 
1 files changed, 18 insertions, 1 deletions
| diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee index 85062c49..425ff47e 100644 --- a/background_scripts/completion_engines.coffee +++ b/background_scripts/completion_engines.coffee @@ -176,7 +176,7 @@ CompletionEngines =      # to generate a key.  We mix in some junk generated by pwgen. A key clash might be possible, but      # vanishingly unlikely.      junk = "//Zi?ei5;o//" -    completionCacheKey = searchUrl + junk + queryTerms.join junk +    completionCacheKey = searchUrl + junk + queryTerms.map((s) -> s.toLowerCase()).join junk      @completionCache ?= new SimpleCache 60 * 60 * 1000, 2000 # One hour, 2000 entries.      if @completionCache.has completionCacheKey        # We add a short delay, even for a cache hit.  This avoids an ugly flicker when the additional @@ -186,6 +186,21 @@ CompletionEngines =          callback @completionCache.get completionCacheKey        return +    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() @@ -227,6 +242,8 @@ CompletionEngines =          queue = @inTransit[completionCacheKey] = []          engine = @lookupEngine searchUrl          fetchSuggestions engine, (suggestions) => +          @mostRecentQuery = queryTerms.join " " +          @mostRecentSuggestions = suggestions            @completionCache.set completionCacheKey, suggestions unless engine.doNotCache            callback suggestions            delete @inTransit[completionCacheKey] | 
