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.
This commit is contained in:
Nathan Sobo
2014-04-03 18:40:55 -06:00
parent 95bf08dfa0
commit fd2ed9a1bc

View File

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