Fix bug and clarify async autocomplete result gathering

@SamyPesse’s “left: total - (i + 1)” was flawed because it only would
work if all completers were async
This commit is contained in:
Aaron O'Mullan 2014-02-08 00:50:50 +01:00
commit cbbbf1c539

View file

@ -206,7 +206,7 @@ var Autocomplete = function() {
callback(null, {
prefix: prefix,
matches: matches,
left: total - (i + 1)
finished: (--total === 0)
});
});
});
@ -255,8 +255,9 @@ var Autocomplete = function() {
// Save current gatherCompletions session, session is close when a match is insert
var _id = this.gatherCompletionsId;
this.gatherCompletions(this.editor, function(err, results) {
// Only detach if result gathering is finished
var doDetach = function() {
if (results.left > 0) return;
if (!results.finished) return;
return this.detach();
}.bind(this);