From 5d82dcf87a14a49c6d647975c202f425a242442f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 15 Mar 2017 12:08:38 -0600 Subject: [PATCH] Wait for content width to update before autoscrolling horizontally --- spec/text-editor-component-spec.js | 13 +++++++++++++ src/text-editor-component.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 7e94ed810..942504131 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -391,6 +391,19 @@ describe('TextEditorComponent', () => { ) expect(scroller.scrollLeft).toBe(expectedScrollLeft) }) + + it('correctly autoscrolls after inserting a line that exceeds the current content width', async () => { + const {component, element, editor} = buildComponent() + const {scroller} = component.refs + element.style.width = component.getScrollWidth() + 'px' + await component.getNextUpdatePromise() + + editor.setCursorScreenPosition([0, Infinity]) + editor.insertText('x'.repeat(100)) + await component.getNextUpdatePromise() + + expect(scroller.scrollLeft).toBe(component.getScrollWidth() - scroller.clientWidth) + }) }) describe('line and line number decorations', () => { diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 0fbbd31a2..c8248dcce 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -107,11 +107,11 @@ class TextEditorComponent { this.measureHorizontalPositions() if (longestLineToMeasure) this.measureLongestLineWidth(longestLineToMeasure) - if (this.pendingAutoscroll) this.finalizeAutoscroll() this.updateAbsolutePositionedDecorations() etch.updateSync(this) + if (this.pendingAutoscroll) this.finalizeAutoscroll() this.currentFrameLineNumberGutterProps = null }