aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/completion_search.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-06-06 06:18:35 +0100
committerStephen Blott2015-06-06 06:46:32 +0100
commitf5db9ea1dc8d23dff732dd3345bf85798d64f1e9 (patch)
treef8aff705dfe0a666f3ba53190a2c35799c689f0c /background_scripts/completion_search.coffee
parent97e5da6cbdcf1b5cf4f80cf550fc26c1ce194a3e (diff)
downloadvimium-f5db9ea1dc8d23dff732dd3345bf85798d64f1e9.tar.bz2
Re-work completions: initial refactor.
The original completion-engine interface was based on three functions. With some experience, it seems there is a pattern involving explicit regular expressions which is used by all actual engine implementations. This is a refactoring to make those regular expressions explicit (and required), and is a first step towards adding additional fucntionality. This also simplifies the completion cache key (use JSON instead of some weird hash).
Diffstat (limited to 'background_scripts/completion_search.coffee')
-rw-r--r--background_scripts/completion_search.coffee7
1 files changed, 1 insertions, 6 deletions
diff --git a/background_scripts/completion_search.coffee b/background_scripts/completion_search.coffee
index d89eb278..cb819025 100644
--- a/background_scripts/completion_search.coffee
+++ b/background_scripts/completion_search.coffee
@@ -58,12 +58,7 @@ CompletionSearch =
return callback [] if 1 == queryTerms.length and Utils.isUrl query
return callback [] if Utils.hasJavascriptPrefix query
- # Cache completions. However, completions depend upon both the searchUrl and the query terms. So we need
- # to generate a key. We mix in some junk generated by pwgen. A key clash might be possible, but
- # is vanishingly unlikely.
- junk = "//Zi?ei5;o//"
- completionCacheKey = searchUrl + junk + queryTerms.map((s) -> s.toLowerCase()).join junk
-
+ completionCacheKey = JSON.stringify [ searchUrl, queryTerms ]
if @completionCache.has completionCacheKey
console.log "hit", completionCacheKey if @debug
return callback @completionCache.get completionCacheKey