From 12f466460d7187cfe37593dab1fbe275403fedd3 Mon Sep 17 00:00:00 2001 From: Alice Koreman Date: Thu, 28 Dec 2023 13:28:46 +0100 Subject: [PATCH] fix: update ghost text if on same line popup --- src/autocomplete.js | 4 ++-- src/autocomplete_test.js | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/autocomplete.js b/src/autocomplete.js index bdd3c1dbf64..bb0bfea1c21 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -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) { diff --git a/src/autocomplete_test.js b/src/autocomplete_test.js index 631193a305c..0398948fbf3 100644 --- a/src/autocomplete_test.js +++ b/src/autocomplete_test.js @@ -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); } };