mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user