From fd2ed9a1bc4a459d94da0174bd4d6116081fda06 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 3 Apr 2014 18:40:55 -0600 Subject: [PATCH] Prevent scroll event feedback loops after scrolling via the model layer When scrolling via the model layer, such as happens on autoscroll due to moving the cursor, we update the scroll position of the fake vertical scrollbar manually. When we receive the scroll event that results from this, we want to do nothing. The best way to determine whether we're getting a "real" scroll event from the user or feedback from setting the scrollTop ourselves is to compare the scrollTop to what's in the model. If the values are equal, there's no need to request an animation frame to assign it. This improves performance. --- src/editor-component.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 1786e2b4c..8a3273162 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -245,8 +245,11 @@ EditorCompont = React.createClass @refs.hiddenInput.focus() onVerticalScroll: -> + scrollTop = @refs.verticalScrollbar.getDOMNode().scrollTop + return if @props.editor.getScrollTop() is scrollTop + animationFramePending = @pendingScrollTop? - @pendingScrollTop = @refs.verticalScrollbar.getDOMNode().scrollTop + @pendingScrollTop = scrollTop unless animationFramePending requestAnimationFrame => @props.editor.setScrollTop(@pendingScrollTop)