From 6e6dce21eecacfe3f7f731b2f7f04fd38338e4bf Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 11 Apr 2017 15:42:22 -0600 Subject: [PATCH] Don't re-measure if editor has become invisible --- spec/text-editor-component-spec.js | 8 ++++++++ src/text-editor-component.js | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 8f0e154a3..980060734 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -2236,6 +2236,14 @@ describe('TextEditorComponent', () => { expect(element.querySelectorAll('.line:not(.dummy)').length).toBeLessThan(initialRenderedLineCount) verifyCursorPosition(component, cursorNode, 1, 29) }) + + it('gracefully handles the editor being hidden after a styling change', async () => { + const {component, element, editor} = buildComponent({autoHeight: false}) + element.style.fontSize = parseInt(getComputedStyle(element).fontSize) + 5 + 'px' + TextEditor.didUpdateStyles() + element.style.display = 'none' + await component.getNextUpdatePromise() + }) }) }) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 183a50ed6..925ee8722 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -166,15 +166,23 @@ class TextEditorComponent { } updateSync (useScheduler = false) { + this.updateScheduled = false + + // Don't proceed if we know we are not visible if (!this.visible) return - this.updateScheduled = false - if (this.resolveNextUpdatePromise) this.resolveNextUpdatePromise() + // Don't proceed if we have to pay for a measurement anyway and detect + // that we are no longer visible. + if ((this.remeasureCharacterDimensions || this.remeasureAllBlockDecorations) && !this.isVisible()) { + if (this.resolveNextUpdatePromise) this.resolveNextUpdatePromise() + return + } const onlyBlinkingCursors = this.nextUpdateOnlyBlinksCursors this.nextUpdateOnlyBlinksCursors = null if (onlyBlinkingCursors) { this.updateCursorBlinkSync() + if (this.resolveNextUpdatePromise) this.resolveNextUpdatePromise() return } @@ -202,6 +210,8 @@ class TextEditorComponent { this.measuredContent = true this.updateSyncAfterMeasuringContent() } + + if (this.resolveNextUpdatePromise) this.resolveNextUpdatePromise() } measureBlockDecorations () {