aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhil Crosby2012-05-05 00:14:46 -0700
committerPhil Crosby2012-05-05 18:32:13 -0700
commit9681a747e7cb5ae8d4348188aa82fd2929efb70e (patch)
tree658dd924df26c726649e083269c9d305688d55aa /lib
parent63e66ffd7def88563ab3f705fe91eea85118cb85 (diff)
downloadvimium-9681a747e7cb5ae8d4348188aa82fd2929efb70e.tar.bz2
Shorten MultiCompleter
Diffstat (limited to 'lib')
-rw-r--r--lib/completion.js27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/completion.js b/lib/completion.js
index fa2e9209..fe616d44 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -279,15 +279,15 @@ var completion = (function() {
/** A meta-completer that delegates queries and merges and sorts the results of a collection of other
* completer instances given in :sources. The optional argument :queryThreshold determines how long a
* query has to be to trigger a search. */
- var MultiCompleter = function(sources, queryThreshold) {
- if (queryThreshold === undefined)
- queryThreshold = 1; // default
- this.sources = sources;
- this.queryThreshold = queryThreshold;
- }
+ var MultiCompleter = Class.extend({
+ init: function(sources, queryThreshold) {
+ if (queryThreshold === undefined)
+ queryThreshold = 1; // default
+ this.sources = sources;
+ this.queryThreshold = queryThreshold;
+ },
- MultiCompleter.prototype = {
- refresh: function() { this.sources.forEach(function(x) { x.refresh(); }); },
+ refresh: function() { this.sources.forEach(function(source) { source.refresh(); }); },
filter: function(query, maxResults, callback) {
if (query.length < this.queryThreshold) {
@@ -295,24 +295,23 @@ var completion = (function() {
return;
}
- var self = this;
- var all = [];
+ var allResults = [];
var counter = this.sources.length;
this.sources.forEach(function(source) {
source.filter(query, function(results) {
- all = all.concat(results);
+ allResults = allResults.concat(results);
if (--counter > 0)
return;
// all sources have provided results by now, so we can sort and return
- all.sort(function(a,b) { return a.relevancy - b.relevancy; });
+ allResults.sort(function(a,b) { return a.relevancy - b.relevancy; });
// evalulate lazy completions for the top n results
- callback(all.slice(0, maxResults).map(function(result) { return result.build(); }));
+ callback(allResults.slice(0, maxResults).map(function(result) { return result.build(); }));
});
});
}
- }
+ });
/** Singleton object that provides helpers and caching for fuzzy completion. */
var fuzzyMatcher = (function() {