diff --git a/src/autocomplete.js b/src/autocomplete.js index 3fbd71dbbfd..5dadc4e5a4b 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -611,7 +611,7 @@ class CompletionProvider { // TODO add support for options.deleteSuffix if (!this.completions) return false; - if (this.completions.filterText) { + if (this.completions.filterText && !data.range) { var ranges; if (editor.selection.getAllRanges) { ranges = editor.selection.getAllRanges(); diff --git a/src/autocomplete_test.js b/src/autocomplete_test.js index 11d2f980a98..34a1e479e00 100644 --- a/src/autocomplete_test.js +++ b/src/autocomplete_test.js @@ -32,6 +32,13 @@ function initEditor(value) { return editor; } +function afterRenderCheck(popup, callback) { + popup.renderer.on("afterRender", function wait() { + popup.renderer.off("afterRender", wait); + callback(); + }); +} + module.exports = { tearDown: function() { if (editor) { @@ -95,7 +102,7 @@ module.exports = { snippet: "will: $1", meta: "snippet", command: "startAutocomplete", - range: new Range(0, 4, 0, 6) + range: new Range(0, 4, 0, 7) }, { caption: "here", value: "-here", @@ -110,12 +117,12 @@ module.exports = { editor.moveCursorTo(0, 6); sendKey("w"); var popup = editor.completer.popup; - check(function () { + afterRenderCheck(popup, function () { assert.equal(popup.data.length, 1); editor.onCommandKey(null, 0, 13); assert.equal(popup.data.length, 2); assert.equal(editor.getValue(), "goodwill: "); - check(function () { + afterRenderCheck(popup, function () { editor.onCommandKey(null, 0, 13); assert.equal(editor.getValue(), "goodwill-here"); editor.destroy(); @@ -123,14 +130,37 @@ module.exports = { done(); }); }); - - function check(callback) { - popup = editor.completer.popup; - popup.renderer.on("afterRender", function wait() { - popup.renderer.off("afterRender", wait); - callback(); - }); - } + }, + "test: filterText does not trigger selection range removal when completions range is present": function (done) { + var editor = initEditor("{}"); + editor.completers = [ + { + getCompletions: function (editor, session, pos, prefix, callback) { + var completions = [ + { + caption: "apple", + snippet: "apple: $1", + meta: "snippet", + range: new Range(0, 1, 0, 2) + }, { + caption: "pineapple", + value: "pineapple", + range: new Range(0, 1, 0, 2) + } + ]; + callback(null, completions); + } + } + ]; + editor.moveCursorTo(0, 1); + sendKey("a"); + var popup = editor.completer.popup; + afterRenderCheck(popup, function () { + assert.equal(popup.data.length, 2); + editor.onCommandKey(null, 0, 13); + assert.equal(editor.getValue(), "{apple: }"); + done(); + }); }, "test: different completers tooltips": function (done) { var editor = initEditor("");