mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Avoid requesting horizontal measurement when auto-scrolling vertically
This was leaving a measurement request in the map that was getting picked up on the next frame. In some cases, the requested measurement row was not present, causing an exception.
This commit is contained in:
committed by
Antonio Scandurra
parent
1b1973db15
commit
c5c48094ba
@@ -826,9 +826,9 @@ describe('TextEditorComponent', () => {
|
||||
})
|
||||
|
||||
it('accounts for the presence of horizontal scrollbars that appear during the same frame as the autoscroll', async () => {
|
||||
const {component, element, editor} = buildComponent()
|
||||
const {component, element, editor} = buildComponent({autoHeight: false})
|
||||
const {scrollContainer} = component.refs
|
||||
element.style.height = component.getScrollHeight() + 'px'
|
||||
element.style.height = component.getContentHeight() / 2 + 'px'
|
||||
element.style.width = component.getScrollWidth() + 'px'
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
@@ -838,6 +838,13 @@ describe('TextEditorComponent', () => {
|
||||
|
||||
expect(component.getScrollTop()).toBe(component.getScrollHeight() - component.getScrollContainerClientHeight())
|
||||
expect(component.getScrollLeft()).toBe(component.getScrollWidth() - component.getScrollContainerClientWidth())
|
||||
|
||||
// Scrolling to the top should not throw an error. This failed
|
||||
// previously due to horizontalPositionsToMeasure not being empty after
|
||||
// autoscrolling vertically to account for the horizontal scrollbar.
|
||||
spyOn(window, 'onerror')
|
||||
await setScrollTop(component, 0)
|
||||
expect(window.onerror).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -311,7 +311,12 @@ class TextEditorComponent {
|
||||
|
||||
updateSyncBeforeMeasuringContent () {
|
||||
this.derivedDimensionsCache = {}
|
||||
if (this.pendingAutoscroll) this.autoscrollVertically()
|
||||
if (this.pendingAutoscroll) {
|
||||
const {screenRange, options} = this.pendingAutoscroll
|
||||
this.autoscrollVertically(screenRange, options)
|
||||
this.requestHorizontalMeasurement(screenRange.start.row, screenRange.start.column)
|
||||
this.requestHorizontalMeasurement(screenRange.end.row, screenRange.end.column)
|
||||
}
|
||||
this.populateVisibleRowRange()
|
||||
this.queryScreenLinesToRender()
|
||||
this.queryLineNumbersToRender()
|
||||
@@ -339,9 +344,10 @@ class TextEditorComponent {
|
||||
|
||||
if (this.pendingAutoscroll) {
|
||||
this.derivedDimensionsCache = {}
|
||||
this.autoscrollHorizontally()
|
||||
const {screenRange, options} = this.pendingAutoscroll
|
||||
this.autoscrollHorizontally(screenRange, options)
|
||||
if (!wasHorizontalScrollbarVisible && this.isHorizontalScrollbarVisible()) {
|
||||
this.autoscrollVertically()
|
||||
this.autoscrollVertically(screenRange, options)
|
||||
}
|
||||
this.pendingAutoscroll = null
|
||||
}
|
||||
@@ -1860,16 +1866,11 @@ class TextEditorComponent {
|
||||
}
|
||||
}
|
||||
|
||||
autoscrollVertically () {
|
||||
const {screenRange, options} = this.pendingAutoscroll
|
||||
|
||||
autoscrollVertically (screenRange, options) {
|
||||
const screenRangeTop = this.pixelPositionAfterBlocksForRow(screenRange.start.row)
|
||||
const screenRangeBottom = this.pixelPositionAfterBlocksForRow(screenRange.end.row) + this.getLineHeight()
|
||||
const verticalScrollMargin = this.getVerticalAutoscrollMargin()
|
||||
|
||||
this.requestHorizontalMeasurement(screenRange.start.row, screenRange.start.column)
|
||||
this.requestHorizontalMeasurement(screenRange.end.row, screenRange.end.column)
|
||||
|
||||
let desiredScrollTop, desiredScrollBottom
|
||||
if (options && options.center) {
|
||||
const desiredScrollCenter = (screenRangeTop + screenRangeBottom) / 2
|
||||
@@ -1901,10 +1902,9 @@ class TextEditorComponent {
|
||||
return false
|
||||
}
|
||||
|
||||
autoscrollHorizontally () {
|
||||
autoscrollHorizontally (screenRange, options) {
|
||||
const horizontalScrollMargin = this.getHorizontalAutoscrollMargin()
|
||||
|
||||
const {screenRange, options} = this.pendingAutoscroll
|
||||
const gutterContainerWidth = this.getGutterContainerWidth()
|
||||
let left = this.pixelLeftForRowAndColumn(screenRange.start.row, screenRange.start.column) + gutterContainerWidth
|
||||
let right = this.pixelLeftForRowAndColumn(screenRange.end.row, screenRange.end.column) + gutterContainerWidth
|
||||
|
||||
Reference in New Issue
Block a user