Skip to content

Commit

Permalink
fix: update ghost text if on same line popup
Browse files Browse the repository at this point in the history
  • Loading branch information
akoreman committed Dec 28, 2023
1 parent 142b607 commit 12f4664
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ class Autocomplete {

this.popup.setRow(this.autoSelect ? newRow : -1);

// If we stay on the same row, but the content is different, we want to update the popup.
if (newRow === oldRow && previousSelectedItem !== this.completions.filtered[newRow])
// If we stay on the same row, but the content is different or we have inline preview enabled, we want to update the popup.
if (newRow === oldRow && (previousSelectedItem !== this.completions.filtered[newRow] || this.inlineRenderer))
this.$onPopupChange();

if (!keepPopupPosition) {
Expand Down
46 changes: 46 additions & 0 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,52 @@ module.exports = {
assert.ok(!(completer.popup && completer.popup.isOpen));

done();
},
"test: should update inline preview when typing when it's the only item in the popup": function(done) {
var editor = initEditor("");

editor.completers = [
{
getCompletions: function (editor, session, pos, prefix, callback) {
var completions = [
{
caption: "function",
value: "function\nthat does something\ncool"
}
];
callback(null, completions);
}
}
];

var completer = Autocomplete.for(editor);
completer.inlineEnabled = true;

user.type("f");
var inline = completer.inlineRenderer;

// Popup should be open, with inline text renderered.
assert.equal(completer.popup.isOpen, true);
assert.equal(completer.popup.getRow(), 0);
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "unction\nthat does something\ncool");

// when you keep typing, the ghost text should update accordingly
user.type("unc");

setTimeout(() => {
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "tion\nthat does something\ncool");

user.type("tio");

setTimeout(() => {
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "n\nthat does something\ncool");

done();
}, 100);
}, 100);
}
};

Expand Down

0 comments on commit 12f4664

Please sign in to comment.