Don't autoscroll to impossible scrollTop locations

This commit is contained in:
Nathan Sobo
2017-02-28 17:44:52 -07:00
committed by Antonio Scandurra
parent d929720d24
commit 19db16664f

View File

@@ -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