diff options
| -rw-r--r-- | fuzzyMode.js | 19 | ||||
| -rw-r--r-- | lib/completion.js | 13 |
2 files changed, 16 insertions, 16 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js index 1edb18f0..cfa8656f 100644 --- a/fuzzyMode.js +++ b/fuzzyMode.js @@ -18,14 +18,14 @@ var fuzzyMode = (function() { else if (name === 'tabs') return new completion.FuzzyTabCompleter(); else if (name === 'tabsSorted') - return new completion.MergingCompleter([getCompleter('tabs')]); + return new completion.MergingCompleter([getCompleter('tabs')], 0); else if (name === 'all') return new completion.MergingCompleter([ getCompleter('smart'), getCompleter('bookmarks'), getCompleter('history'), getCompleter('tabs'), - ]); + ], 1); } function getCompleter(name) { if (!(name in completers)) @@ -49,7 +49,6 @@ var fuzzyMode = (function() { this.maxResults = maxResults; this.refreshInterval = refreshInterval; this.initDom(); - this.reset(); } FuzzyBox.prototype = { setCompleter: function(completer) { @@ -141,17 +140,7 @@ var fuzzyMode = (function() { return true; }, - updateInput: function() { - this.query = this.query.replace(/^\s*/, ''); - this.input.textContent = this.query; - }, - updateCompletions: function() { - if (this.query.length == 0) { - this.completionList.style.display = 'none'; - return; - } - var self = this; this.completer.filter(this.query, function(completions) { self.completions = completions.slice(0, self.maxResults); @@ -168,7 +157,9 @@ var fuzzyMode = (function() { update: function(sync) { sync = sync || false; // explicitely default to asynchronous updating - this.updateInput(); + + this.query = this.query.replace(/^\s*/, ''); + this.input.textContent = this.query; if (sync) { this.updateCompletions(); diff --git a/lib/completion.js b/lib/completion.js index d36dc2e5..b5793437 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -449,9 +449,13 @@ var completion = (function() { } /** A meta-completer that delegates queries and merges and sorts the results of a collection of other - * completer instances. */ - var MergingCompleter = function(sources) { + * completer instances given in :sources. The optional argument :queryThreshold determines how long a + * query has to be to trigger a refresh. */ + var MergingCompleter = function(sources, queryThreshold) { + if (queryThreshold === undefined) + queryThreshold = 1; // default this.sources = sources; + this.queryThreshold = queryThreshold; } MergingCompleter.prototype = { refresh: function() { @@ -459,6 +463,11 @@ var completion = (function() { }, filter: function(query, callback) { + if (query.length < this.queryThreshold) { + callback([]); + return; + } + var all = []; var counter = this.sources.length; |
