From bdfca8b9021c5c14c498e1ec4d4e9d729e7860da Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 9 Feb 2015 14:36:30 -0700 Subject: [PATCH] Coalesce handling style sheet changes in editor with nextAnimationFrame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we were delaying handling, but still requesting redundant handling by requesting multiple frames. Now we don’t request a new update if there is already one outstanding. --- src/text-editor-component.coffee | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index 5f13945a2..0a2db643e 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -39,6 +39,7 @@ TextEditorComponent = React.createClass measureScrollbarsWhenShown: true measureLineHeightAndDefaultCharWidthWhenShown: true remeasureCharacterWidthsWhenShown: false + stylingChangeAnimationFrameRequested: false render: -> {focused, showLineNumbers} = @state @@ -508,10 +509,14 @@ TextEditorComponent = React.createClass # This delay prevents the styling from going haywire when stylesheets are # reloaded in dev mode. It seems like a workaround for a browser bug, but # not totally sure. - requestAnimationFrame => - if @isMounted() - @refreshScrollbars() if not styleElement.sheet? or @containsScrollbarSelector(styleElement.sheet) - @handleStylingChange() + + unless @stylingChangeAnimationFrameRequested + @stylingChangeAnimationFrameRequested = true + requestAnimationFrame => + @stylingChangeAnimationFrameRequested = false + if @isMounted() + @refreshScrollbars() if not styleElement.sheet? or @containsScrollbarSelector(styleElement.sheet) + @handleStylingChange() onAllThemesLoaded: -> @refreshScrollbars()