Skip to content

Commit 529473b

Browse files
authored
fix: scroll cursor line to top editor for long inline preview (#5514)
* fix: scroll cursor to top for long inline preview * fix: calculation of pixels to scroll top in setGhostText * revert: changes to pixelposition calc * fix: whitespace
1 parent 099011b commit 529473b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/autocomplete/inline_test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,15 @@ module.exports = {
274274
// of the container
275275
editor.execCommand("insertstring", "\n".repeat(200));
276276

277-
var deltaY;
277+
var deltaY, row;
278278
var initialScrollBy = editor.renderer.scrollBy;
279-
editor.renderer.scrollBy = function(varX, varY) {
279+
var initialScrollToRow = editor.renderer.scrollToRow;
280+
editor.renderer.scrollBy = function(_, varY) {
280281
deltaY = varY;
281282
};
283+
editor.renderer.scrollToRow = function(varRow) {
284+
row = varRow;
285+
};
282286

283287
inline.show(editor, completions[6], "l");
284288
editor.renderer.$loop._flush();
@@ -295,8 +299,9 @@ module.exports = {
295299

296300
setTimeout(() => {
297301
// Should scroll as much as possbile while keeping the cursor on screen
298-
assert.strictEqual(deltaY, 490);
302+
assert.strictEqual(row, 202);
299303
editor.renderer.scrollBy = initialScrollBy;
304+
editor.renderer.scrollToRow = initialScrollToRow;
300305
done();
301306
}, 50);
302307
}, 50);

src/virtual_renderer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1781,18 +1781,18 @@ class VirtualRenderer {
17811781
var el = this.container;
17821782
var height = el.getBoundingClientRect().height;
17831783
var ghostTextHeight = textLines.length * this.lineHeight;
1784-
var fitsY = ghostTextHeight < height - pixelPosition.top;
1784+
var fitsY = ghostTextHeight < (height - pixelPosition.top);
17851785

17861786
// If it fits, no action needed
17871787
if (fitsY) return;
17881788

17891789
// If it can fully fit in the screen, scroll down until it fits on the screen
1790-
// if it cannot fully fit, scroll so that the cursor is at the top of the screen
1791-
// to fit as much as possible.
1790+
// if it cannot fully fit, scroll so that the row with the cursor
1791+
// is at the top of the screen.
17921792
if (ghostTextHeight < height) {
17931793
this.scrollBy(0, (textLines.length - 1) * this.lineHeight);
17941794
} else {
1795-
this.scrollBy(0, pixelPosition.top);
1795+
this.scrollToRow(insertPosition.row);
17961796
}
17971797
}
17981798

0 commit comments

Comments
 (0)