Skip to content

Commit 1ae0bdc

Browse files
authored
fix: ghost text rendering of empty lines (#5615)
* fix: ghost text rendering of empty lines
1 parent ed233cf commit 1ae0bdc

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/autocomplete/inline_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ var completions = [
5050
{
5151
value: "long\nlong\nlong\nlong\nlong\nlong".repeat(100),
5252
score: 0
53+
},
54+
{
55+
value: "foo suggestion with a\n\n\ngap",
56+
score: 0
5357
}
5458
];
5559

@@ -305,6 +309,14 @@ module.exports = {
305309
}, 50);
306310
}, 50);
307311
},
312+
"test: renders multi-line ghost text with empty lines": function(done) {
313+
assert.equal(editor.renderer.$ghostTextWidget, null);
314+
inline.show(editor, completions[8], "f");
315+
editor.renderer.$loop._flush();
316+
assert.strictEqual(getAllLines(), textBase + "foo suggestion with a");
317+
assert.strictEqual(editor.renderer.$ghostTextWidget.el.innerHTML, `<div> </div><div> </div><div>gap</div>`);
318+
done();
319+
},
308320
tearDown: function() {
309321
inline.destroy();
310322
editor.destroy();

src/virtual_renderer.js

+4
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,10 @@ class VirtualRenderer {
17851785
// If the line is wider than the viewport, wrap the line
17861786
if (el.wrapped) chunkDiv.className = "ghost_text_line_wrapped";
17871787

1788+
// If a given line doesn't have text (e.g. it's a line of whitespace), set a space as the
1789+
// textcontent so that browsers render the empty line div.
1790+
if (el.text.length === 0) el.text = " ";
1791+
17881792
chunkDiv.appendChild(dom.createTextNode(el.text));
17891793
widgetDiv.appendChild(chunkDiv);
17901794
});

src/virtual_renderer_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ module.exports = {
395395
editor.renderer.$loop._flush();
396396
assert.equal(editor.renderer.content.textContent, "abcdefThis is a long test text that is longer than ");
397397

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

400400
editor.removeGhostText();
401401

0 commit comments

Comments
 (0)