diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 3333c1d1d..614802eda 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -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() }) }) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 51da03222..ae4db7f9d 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -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