From 48abb16edbb105e41c2558c88a31ab45a2a3ba6c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 18 Jul 2017 14:31:47 -0700 Subject: [PATCH] Fix exception in screenPositionForPixelPosition when content updates are pending Signed-off-by: Nathan Sobo --- spec/text-editor-component-spec.js | 9 +++++++++ src/text-editor-component.js | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 7a4608872..cb21f68a3 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -3335,6 +3335,15 @@ describe('TextEditorComponent', () => { expect(left).toBe(clientLeftForCharacter(referenceComponent, 12, 1) - referenceContentRect.left) } }) + + it('does not get the component into an inconsistent state when the model has unflushed changes (regression)', async () => { + const {component, element, editor} = buildComponent({rowsPerTile: 2, autoHeight: false, text: ''}) + await setEditorHeightInLines(component, 10) + + const updatePromise = editor.getBuffer().append("hi\n") + component.screenPositionForPixelPosition({top: 800, left: 1}) + await updatePromise + }) }) describe('screenPositionForPixelPosition', () => { diff --git a/src/text-editor-component.js b/src/text-editor-component.js index a3a51a3aa..bffa5db50 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -251,20 +251,17 @@ class TextEditorComponent { this.measureBlockDecorations() - this.measuredContent = false this.updateSyncBeforeMeasuringContent() if (useScheduler === true) { const scheduler = etch.getScheduler() scheduler.readDocument(() => { this.measureContentDuringUpdateSync() - this.measuredContent = true scheduler.updateDocument(() => { this.updateSyncAfterMeasuringContent() }) }) } else { this.measureContentDuringUpdateSync() - this.measuredContent = true this.updateSyncAfterMeasuringContent() } } @@ -341,6 +338,7 @@ class TextEditorComponent { } updateSyncBeforeMeasuringContent () { + this.measuredContent = false this.derivedDimensionsCache = {} this.updateModelSoftWrapColumn() if (this.pendingAutoscroll) { @@ -384,6 +382,8 @@ class TextEditorComponent { } this.pendingAutoscroll = null } + + this.measuredContent = true } updateSyncAfterMeasuringContent () {