From cbbbf1c539ee84abf499c3601369545fd37b680f Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sat, 8 Feb 2014 00:50:50 +0100 Subject: [PATCH] Fix bug and clarify async autocomplete result gathering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @SamyPesse’s “left: total - (i + 1)” was flawed because it only would work if all completers were async --- lib/ace/autocomplete.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ace/autocomplete.js b/lib/ace/autocomplete.js index c5109ae1..8bf3a401 100644 --- a/lib/ace/autocomplete.js +++ b/lib/ace/autocomplete.js @@ -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);