Skip to content

Commit

Permalink
fix: filterText triggered selection range removal when completions ra…
Browse files Browse the repository at this point in the history
…nge was present (#5249)
  • Loading branch information
mkslanc authored Jul 12, 2023
1 parent 0e36379 commit b586e4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
52 changes: 41 additions & 11 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand All @@ -110,27 +117,50 @@ 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();
editor.container.remove();
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("");
Expand Down

0 comments on commit b586e4d

Please sign in to comment.