Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve prefixing for inline preview #5439

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ class Autocomplete {
}

$updateGhostText(completion) {
var prefix = util.getCompletionPrefix(this.editor);
// Ghost text can include characters normally not part of the prefix (e.g. whitespace).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why getCompletionPrefix in utils doesn't consider whitespaces? Should we update that too?

// When typing ahead with ghost text however, we want to simply prefix with respect to the
// base of the completion.
var row = this.base.row;
var column = this.base.column;
var cursorColumn = this.editor.getCursorPosition().column;
var prefix = this.editor.session.getLine(row).slice(column, cursorColumn);

if (!this.inlineRenderer.show(this.editor, completion, prefix)) {
this.inlineRenderer.hide();
} else {
Expand Down
45 changes: 45 additions & 0 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict";

var sendKey = require("./test/user").type;
var {buildDom} = require("./lib/dom");

Check warning on line 8 in src/autocomplete_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'buildDom' is assigned a value but never used
var ace = require("./ace");
var assert = require("./test/assertions");
var user = require("./test/user");
Expand Down Expand Up @@ -1383,6 +1383,51 @@
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "n\nthat does something\ncool");

done();
}, 100);
}, 100);
},
"test: should keep showing ghost text when typing ahead with whitespace": function(done) {
var editor = initEditor("");

editor.completers = [
{
getCompletions: function (editor, session, pos, prefix, callback) {
var completions = [
{
value: "function that does something cool"
}
];
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 that does something cool");

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

setTimeout(() => {
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "at does something cool");

user.type("at do");

setTimeout(() => {
assert.strictEqual(inline.isOpen(), true);
assert.strictEqual(editor.renderer.$ghostText.text, "es something cool");

done();
}, 100);
}, 100);
Expand Down
Loading