From 9a0709e95ed64a5c3670f9d47db6093b1821471c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 7 Jun 2017 18:59:23 +0200 Subject: [PATCH 1/2] Don't try to measure lines that don't exist By the time that the animation frame is delivered, the requested autoscroll position could not exist anymore. This could cause the editor component to measure a non-existent line and, as a result, throw an exception. With this commit we will always ignore measurements for screen lines that do not exist. --- spec/text-editor-component-spec.js | 10 +++++++++- src/text-editor-component.js | 9 +++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 9163b46a7..1b33e3332 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -24,7 +24,7 @@ document.registerElement('text-editor-component-test-element', { }) }) -describe('TextEditorComponent', () => { +fdescribe('TextEditorComponent', () => { beforeEach(() => { jasmine.useRealClock() @@ -961,6 +961,14 @@ describe('TextEditorComponent', () => { expect(component.getScrollLeft()).toBe(component.getScrollWidth() - component.getScrollContainerClientWidth()) }) + it('does not try to measure lines that do not exist when the animation frame is delivered', async () => { + const {component, editor} = buildComponent({autoHeight: false, height: 30, rowsPerTile: 2}) + editor.scrollToBufferPosition([11, 5]) + editor.getBuffer().deleteRows(11, 12) + await component.getNextUpdatePromise() + expect(component.getScrollBottom()).toBe((10 + 1) * component.measurements.lineHeight) + }) + it('accounts for the presence of horizontal scrollbars that appear during the same frame as the autoscroll', async () => { const {component, element, editor} = buildComponent({autoHeight: false}) const {scrollContainer} = component.refs diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 58ab2415f..bdef7130e 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -332,7 +332,7 @@ class TextEditorComponent { this.derivedDimensionsCache = {} this.updateModelSoftWrapColumn() if (this.pendingAutoscroll) { - const {screenRange, options} = this.pendingAutoscroll + let {screenRange, options} = this.pendingAutoscroll this.autoscrollVertically(screenRange, options) this.requestHorizontalMeasurement(screenRange.start.row, screenRange.start.column) this.requestHorizontalMeasurement(screenRange.end.row, screenRange.end.column) @@ -2097,7 +2097,12 @@ class TextEditorComponent { if (column === 0) return if (row < this.getRenderedStartRow() || row >= this.getRenderedEndRow()) { - this.requestExtraLineToMeasure(row, this.props.model.screenLineForScreenRow(row)) + const screenLine = this.props.model.screenLineForScreenRow(row) + if (screenLine) { + this.requestExtraLineToMeasure(row, screenLine) + } else { + return + } } let columns = this.horizontalPositionsToMeasure.get(row) From a314deeff98f71ad658ba77187e66e66e5259c59 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 12 Jun 2017 11:27:58 +0200 Subject: [PATCH 2/2] Unfocus test --- spec/text-editor-component-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 1b33e3332..23e5eb8f9 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -24,7 +24,7 @@ document.registerElement('text-editor-component-test-element', { }) }) -fdescribe('TextEditorComponent', () => { +describe('TextEditorComponent', () => { beforeEach(() => { jasmine.useRealClock()