From 19db16664fa0b9de2101afa64eae6de63c0dc5c1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 28 Feb 2017 17:44:52 -0700 Subject: [PATCH] Don't autoscroll to impossible scrollTop locations --- src/text-editor-component.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index f0fc7eb1d..78c3655f9 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -629,6 +629,14 @@ class TextEditorComponent { desiredScrollBottom = screenRangeBottom + verticalScrollMargin } + if (desiredScrollTop != null) { + desiredScrollTop = Math.max(0, Math.min(desiredScrollTop, this.getScrollHeight() - this.getClientHeight())) + } + + if (desiredScrollBottom != null) { + desiredScrollBottom = Math.max(this.getClientHeight(), Math.min(desiredScrollBottom, this.getScrollHeight())) + } + if (!options || options.reversed !== false) { if (desiredScrollBottom > this.getScrollBottom()) { this.autoscrollTop = desiredScrollBottom - this.measurements.clientHeight @@ -845,6 +853,18 @@ class TextEditorComponent { return this.measurements ? this.measurements.scrollLeft : null } + getScrollHeight () { + return this.getModel().getApproximateScreenLineCount() * this.measurements.lineHeight + } + + getScrollWidth () { + return Math.round(this.measurements.longestLineWidth + this.measurements.baseCharacterWidth) + } + + getClientHeight () { + return this.measurements.clientHeight + } + getRowsPerTile () { return this.props.rowsPerTile || DEFAULT_ROWS_PER_TILE } @@ -891,14 +911,6 @@ class TextEditorComponent { return row * this.measurements.lineHeight } - getScrollWidth () { - return Math.round(this.measurements.longestLineWidth + this.measurements.baseCharacterWidth) - } - - getScrollHeight () { - return this.getModel().getApproximateScreenLineCount() * this.measurements.lineHeight - } - getLongestScreenLine () { const model = this.getModel() // Ensure the spatial index is populated with rows that are currently