Skip to content

Commit

Permalink
fix: ghost text rendering of empty lines (#5615)
Browse files Browse the repository at this point in the history
* fix: ghost text rendering of empty lines
  • Loading branch information
akoreman committed Jul 18, 2024
1 parent ed233cf commit 1ae0bdc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/autocomplete/inline_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ var completions = [
{
value: "long\nlong\nlong\nlong\nlong\nlong".repeat(100),
score: 0
},
{
value: "foo suggestion with a\n\n\ngap",
score: 0
}
];

Expand Down Expand Up @@ -305,6 +309,14 @@ module.exports = {
}, 50);
}, 50);
},
"test: renders multi-line ghost text with empty lines": function(done) {
assert.equal(editor.renderer.$ghostTextWidget, null);
inline.show(editor, completions[8], "f");
editor.renderer.$loop._flush();
assert.strictEqual(getAllLines(), textBase + "foo suggestion with a");
assert.strictEqual(editor.renderer.$ghostTextWidget.el.innerHTML, `<div> </div><div> </div><div>gap</div>`);
done();
},
tearDown: function() {
inline.destroy();
editor.destroy();
Expand Down
4 changes: 4 additions & 0 deletions src/virtual_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,10 @@ class VirtualRenderer {
// If the line is wider than the viewport, wrap the line
if (el.wrapped) chunkDiv.className = "ghost_text_line_wrapped";

// If a given line doesn't have text (e.g. it's a line of whitespace), set a space as the
// textcontent so that browsers render the empty line div.
if (el.text.length === 0) el.text = " ";

chunkDiv.appendChild(dom.createTextNode(el.text));
widgetDiv.appendChild(chunkDiv);
});
Expand Down
2 changes: 1 addition & 1 deletion src/virtual_renderer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ module.exports = {
editor.renderer.$loop._flush();
assert.equal(editor.renderer.content.textContent, "abcdefThis is a long test text that is longer than ");

assert.equal(editor.session.lineWidgets[0].el.innerHTML, `<div class="ghost_text_line_wrapped">30 characters</div><div></div><div>Ghost3</div>`);
assert.equal(editor.session.lineWidgets[0].el.innerHTML, `<div class="ghost_text_line_wrapped">30 characters</div><div> </div><div>Ghost3</div>`);

editor.removeGhostText();

Expand Down

0 comments on commit 1ae0bdc

Please sign in to comment.