From 6fefef0509e8ad48478c2f8ad26a628bb292c54c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 22 Mar 2017 16:57:03 -0600 Subject: [PATCH] Only update scrollTop/Left when they change This avoids forcing a reflows in some circumnstances. --- src/text-editor-component.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index b85e30f9b..f72d90175 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1866,13 +1866,26 @@ class DummyScrollbarComponent { constructor (props) { this.props = props etch.initialize(this) - this.updateScrollPosition() + if (this.props.orientation === 'horizontal') { + this.element.scrollLeft = this.props.scrollLeft + } else { + this.element.scrollTop = this.props.scrollTop + } } - update (props) { - this.props = props + update (newProps) { + const oldProps = this.props + this.props = newProps etch.updateSync(this) - this.updateScrollPosition() + if (this.props.orientation === 'horizontal') { + if (newProps.scrollLeft !== oldProps.scrollLeft) { + this.element.scrollLeft = this.props.scrollLeft + } + } else { + if (newProps.scrollTop !== oldProps.scrollTop) { + this.element.scrollTop = this.props.scrollTop + } + } } // Scroll position must be updated after the inner element is updated to