Coalesce handling style sheet changes in editor with nextAnimationFrame

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.
This commit is contained in:
Nathan Sobo
2015-02-09 14:36:30 -07:00
parent df01c8ab6f
commit bdfca8b902

View File

@@ -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()