Combine all updates that occur in an animation frame

This commit is contained in:
Nathan Sobo
2014-06-24 15:46:09 -06:00
parent 0369d77c85
commit 27a959ec16

View File

@@ -25,6 +25,8 @@ EditorComponent = React.createClass
pendingScrollTop: null
pendingScrollLeft: null
selectOnMouseMove: false
updatesPaused: false
updateRequestedWhilePaused: false
updateRequested: false
cursorsMoved: false
selectionChanged: false
@@ -203,20 +205,23 @@ EditorComponent = React.createClass
@remeasureCharacterWidthsIfNeeded(prevState)
requestUpdate: ->
if @performSyncUpdates ? EditorComponent.performSyncUpdates
@forceUpdate()
else unless @updateRequested
@updateRequested = true
process.nextTick =>
@updateRequested = false
@forceUpdate() if @isMounted()
if @updatesPaused
@updateRequestedWhilePaused = true
else
if @performSyncUpdates ? EditorComponent.performSyncUpdates
@forceUpdate()
else unless @updateRequested
@updateRequested = true
process.nextTick =>
@updateRequested = false
@forceUpdate() if @isMounted()
requestAnimationFrame: (fn) ->
prevPerformSyncUpdates = @performSyncUpdates
@performSyncUpdates = true
requestAnimationFrame =>
@updatesPaused = true
fn()
@performSyncUpdates = prevPerformSyncUpdates
@updatesPaused = false
@forceUpdate() if @updateRequestedWhilePaused
getRenderedRowRange: ->
{editor, lineOverdrawMargin} = @props