aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNiklas Baumstark2012-01-24 00:17:30 +0100
committerNiklas Baumstark2012-04-10 23:54:38 +0200
commitf69fea31ad8c1e672f908fdf9debd64a5d0fee5e (patch)
treeca87ad016503da774f9cac83d5f24563039e31fd /lib
parent82b461bbc0851bd3f6e3b3e8d3c4155e48400bcf (diff)
downloadvimium-f69fea31ad8c1e672f908fdf9debd64a5d0fee5e.tar.bz2
more DRYing
Diffstat (limited to 'lib')
-rw-r--r--lib/completion.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/completion.js b/lib/completion.js
index 338ccbbb..35b1d132 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -83,9 +83,9 @@ var completion = (function() {
/** Trims the size of the regex cache to the configured size using a FIFO algorithm. */
self.cleanMatcherCache = function() {
// remove old matchers
- queries = Object.keys(self.matcherCache);
- for (var i = 0; i < queries.length - self.matcherCacheSize; ++i)
+ Object.keys(self.matcherCache).forEach(function(query) {
delete self.matcherCache(queries[i]);
+ });
}
/** Returns a regex that matches a string using a fuzzy :query. Example: The :query "abc" would result
@@ -95,6 +95,7 @@ var completion = (function() {
query = self.normalize(query);
if (!(query in self.matcherCache)) {
// build up a regex for fuzzy matching
+ // TODO use an array and .join here
var regex = '^';
for (var i = 0; i < query.length; ++i)
regex += '([^' + query[i] + ']*)(' + query[i] + ')';
@@ -108,8 +109,6 @@ var completion = (function() {
* results of the last filtering are used as a starting point, instead of :source.
*/
self.filter = function(query, source, getValue, id) {
- var filtered = [];
-
if (!(id in self.filterCache))
self.filterCache[id] = {};
@@ -318,6 +317,8 @@ var completion = (function() {
this.refresh = function() { };
+ // TODO make this shorter and use a more functional way to do it
+
/** Checks if the input is a special command and if yes, add according suggestions to the given array */
this.addCommandSuggestions = function(query, suggestions) {
// check if the input is a special command
@@ -340,6 +341,7 @@ var completion = (function() {
suggestions.push({
render: createConstantFunction('<em>' + desc + '</em> ' + term),
action: createActionOpenUrl(utils.createFullUrl(url)),
+ relevancy: -2, // this will appear even before the URL/search suggestion
});
}
}