aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Baumstark2012-01-21 02:53:57 +0100
committerNiklas Baumstark2012-04-10 23:54:35 +0200
commitbd6f3bebc41792567b31804f3463119b649cb1e1 (patch)
tree8e34597a0fee18425378818616ed48257a0d5c2b
parent2a9c88ae1db8b4eadd5ad815966b1820c5d0af5b (diff)
downloadvimium-bd6f3bebc41792567b31804f3463119b649cb1e1.tar.bz2
fix some issues with asynchronous filtering and refreshing
-rw-r--r--fuzzyMode.js32
-rw-r--r--lib/completion.js17
2 files changed, 20 insertions, 29 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js
index 0387e97b..5588c281 100644
--- a/fuzzyMode.js
+++ b/fuzzyMode.js
@@ -9,6 +9,7 @@ var fuzzyMode = (function() {
'cc ' : [ 'dict.cc', 'http://www.dict.cc/?s=%s' ],
';' : [ 'goto', '%s' ]
}),
+ completer.refresh();
new completion.FuzzyHistoryCompleter(1000),
new completion.FuzzyBookmarkCompleter(),
]);
@@ -27,8 +28,6 @@ var fuzzyMode = (function() {
FuzzyBox.prototype = {
show: function(reverseAction) {
this.reverseAction = reverseAction;
- this.completer.refresh();
- this.update();
this.box.style.display = 'block';
var self = this;
handlerStack.push({ keydown: function(event) { self.onKeydown(event); }});
@@ -106,30 +105,27 @@ var fuzzyMode = (function() {
this.query = this.query.replace(/^\s*/, '');
this.input.textContent = this.query;
- // clear completions
- this.completions = [];
- while (this.completionList.hasChildNodes())
- this.completionList.removeChild(this.completionList.firstChild);
-
if (this.query.length == 0) {
this.completionList.style.display = 'none';
return;
}
-
this.completionList.style.display = 'block';
- var li;
- var counter = 0;
var self = this;
- this.completer.filter(this.query, function(completion) {
- self.completions.push(completion);
- li = document.createElement('li');
- li.innerHTML = completion.render();
- self.completionList.appendChild(li);
- return ++counter < 10;
+ this.completer.filter(this.query, function(completions) {
+ // clear completions
+ self.completions = [];
+ while (self.completionList.hasChildNodes())
+ self.completionList.removeChild(self.completionList.firstChild);
+
+ for (var i = 0; i < completions.length && i < 10; ++i) {
+ self.completions.push(completions[i]);
+ var li = document.createElement('li');
+ li.innerHTML = completions[i].render();
+ self.completionList.appendChild(li);
+ }
+ self.updateSelection();
});
-
- this.updateSelection();
},
initDom: function() {
diff --git a/lib/completion.js b/lib/completion.js
index f713eaa0..c7ac0417 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -146,7 +146,7 @@ var completion = (function() {
var AsyncFuzzyUrlCompleter = function() {
this.completions = null;
this.id = utils.createUniqueId();
- this.readyCallback = function(results) {
+ this.readyCallback = this.fallbackReadyCallback = function(results) {
this.completions = results;
}
}
@@ -164,7 +164,7 @@ var completion = (function() {
var handler = function(results) {
var filtered = [];
fuzzyMatcher.filter(query,
- self.completions, function(comp) { return comp.str },
+ results, function(comp) { return comp.str },
self.id,
function(match) {
filtered.push(createHighlightingCompletion(
@@ -180,12 +180,11 @@ var completion = (function() {
// yes: call the callback synchronously
handler(this.completions);
} else {
- // no: push our handler to the handling chain
- var oldReadyCallback = this.readyCallback;
+ // no: register the handler as a callback
this.readyCallback = function(results) {
handler(results);
- this.readyCallback = oldReadyCallback;
- oldReadyCallback(results);
+ this.readyCallback = this.fallbackReadyCallback;
+ this.readyCallback(results);
}
}
},
@@ -339,11 +338,7 @@ var completion = (function() {
all.sort(function(a,b) {
return a.relevancy - b.relevancy;
});
- for (var i = 0; i < all.length; ++i) {
- if (!callback(all[i]))
- // the caller doesn't want any more results
- return;
- }
+ callback(all);
});
}
}