diff --git a/src/autocomplete/inline_test.js b/src/autocomplete/inline_test.js index 5e0ee5f5c3a..019e4b2a483 100644 --- a/src/autocomplete/inline_test.js +++ b/src/autocomplete/inline_test.js @@ -274,11 +274,15 @@ module.exports = { // of the container editor.execCommand("insertstring", "\n".repeat(200)); - var deltaY; + var deltaY, row; var initialScrollBy = editor.renderer.scrollBy; - editor.renderer.scrollBy = function(varX, varY) { + var initialScrollToRow = editor.renderer.scrollToRow; + editor.renderer.scrollBy = function(_, varY) { deltaY = varY; }; + editor.renderer.scrollToRow = function(varRow) { + row = varRow; + }; inline.show(editor, completions[6], "l"); editor.renderer.$loop._flush(); @@ -295,8 +299,9 @@ module.exports = { setTimeout(() => { // Should scroll as much as possbile while keeping the cursor on screen - assert.strictEqual(deltaY, 490); + assert.strictEqual(row, 202); editor.renderer.scrollBy = initialScrollBy; + editor.renderer.scrollToRow = initialScrollToRow; done(); }, 50); }, 50); diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 4ef7553caac..622cf09ac06 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1781,18 +1781,18 @@ class VirtualRenderer { var el = this.container; var height = el.getBoundingClientRect().height; var ghostTextHeight = textLines.length * this.lineHeight; - var fitsY = ghostTextHeight < height - pixelPosition.top; + var fitsY = ghostTextHeight < (height - pixelPosition.top); // If it fits, no action needed if (fitsY) return; // If it can fully fit in the screen, scroll down until it fits on the screen - // if it cannot fully fit, scroll so that the cursor is at the top of the screen - // to fit as much as possible. + // if it cannot fully fit, scroll so that the row with the cursor + // is at the top of the screen. if (ghostTextHeight < height) { this.scrollBy(0, (textLines.length - 1) * this.lineHeight); } else { - this.scrollBy(0, pixelPosition.top); + this.scrollToRow(insertPosition.row); } }