From 2b54c9bebe20718a9ba5775b2cab119b56ed706e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 25 Jun 2014 18:13:50 -0600 Subject: [PATCH] Use setImmediate to batch all editor updates, even in animation frames When I was using nextTick to batch updates, there were issues with flicker. So I was attempting to always update synchronously in animation frames, which was complicated. setImmediate doesn't cause the flicker however, so I'm able to remove the special logic for sync updates in animation frames and just use it across the board. --- src/editor-component.coffee | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index ba1f0db78..50ab1e7d0 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -25,8 +25,6 @@ EditorComponent = React.createClass pendingScrollTop: null pendingScrollLeft: null selectOnMouseMove: false - updatesPaused: false - updateRequestedWhilePaused: false updateRequested: false cursorsMoved: false selectionChanged: false @@ -205,23 +203,13 @@ EditorComponent = React.createClass @remeasureCharacterWidthsIfNeeded(prevState) requestUpdate: -> - if @updatesPaused - @updateRequestedWhilePaused = true - else - if @performSyncUpdates ? EditorComponent.performSyncUpdates - @forceUpdate() - else unless @updateRequested - @updateRequested = true - process.nextTick => - @updateRequested = false - @forceUpdate() if @isMounted() - - requestAnimationFrame: (fn) -> - requestAnimationFrame => - @updatesPaused = true - fn() - @updatesPaused = false - @forceUpdate() if @updateRequestedWhilePaused + if @performSyncUpdates ? EditorComponent.performSyncUpdates + @forceUpdate() + else unless @updateRequested + @updateRequested = true + setImmediate => + @updateRequested = false + @forceUpdate() if @isMounted() getRenderedRowRange: -> {editor, lineOverdrawMargin} = @props @@ -522,7 +510,7 @@ EditorComponent = React.createClass animationFramePending = @pendingScrollTop? @pendingScrollTop = scrollTop unless animationFramePending - @requestAnimationFrame => + requestAnimationFrame => @props.editor.setScrollTop(@pendingScrollTop) onHorizontalScroll: (scrollLeft) -> @@ -533,7 +521,7 @@ EditorComponent = React.createClass animationFramePending = @pendingScrollLeft? @pendingScrollLeft = scrollLeft unless animationFramePending - @requestAnimationFrame => + requestAnimationFrame => @props.editor.setScrollLeft(@pendingScrollLeft) @pendingScrollLeft = null @@ -554,7 +542,7 @@ EditorComponent = React.createClass @clearMouseWheelScreenRowAfterDelay() unless animationFramePending - @requestAnimationFrame => + requestAnimationFrame => {editor} = @props editor.setScrollTop(editor.getScrollTop() + @pendingVerticalScrollDelta) editor.setScrollLeft(editor.getScrollLeft() + @pendingHorizontalScrollDelta)