Update the scrollLeft of the model when the horizontal scrollbar changes

This commit is contained in:
David Graham & Nathan Sobo
2014-04-08 14:20:19 -06:00
committed by Nathan Sobo
parent 48135a1e8d
commit cfdea7e73f
2 changed files with 23 additions and 0 deletions

View File

@@ -388,3 +388,13 @@ describe "EditorComponent", ->
editor.setScrollLeft(100)
expect(scrollViewContentNode.style['-webkit-transform']).toBe "translate(-100px, 0px)"
expect(horizontalScrollbarNode.scrollLeft).toBe 100
it "updates the scrollLeft of the model when the scrollLeft of the horizontal scrollbar changes", ->
node.style.width = 30 * charWidth + 'px'
component.updateAllDimensions()
expect(editor.getScrollLeft()).toBe 0
node.querySelector('.horizontal-scrollbar').scrollLeft = 100
component.onHorizontalScroll()
expect(editor.getScrollLeft()).toBe 100

View File

@@ -16,6 +16,7 @@ AcceptFilter = {acceptNode: -> NodeFilter.FILTER_ACCEPT}
module.exports =
EditorCompont = React.createClass
pendingScrollTop: null
pendingScrollLeft: null
lastScrollTop: null
selectOnMouseMove: false
@@ -320,6 +321,17 @@ EditorCompont = React.createClass
@props.editor.setScrollTop(@pendingScrollTop)
@pendingScrollTop = null
onHorizontalScroll: ->
scrollLeft = @refs.horizontalScrollbar.getDOMNode().scrollLeft
return if @props.editor.getScrollLeft() is scrollLeft
animationFramePending = @pendingScrollLeft?
@pendingScrollLeft = scrollLeft
unless animationFramePending
requestAnimationFrame =>
@props.editor.setScrollLeft(@pendingScrollLeft)
@pendingScrollLeft = null
onMouseWheel: (event) ->
# To preserve velocity scrolling, delay removal of the event's target until
# after mousewheel events stop being fired. Removing the target before then
@@ -329,6 +341,7 @@ EditorCompont = React.createClass
@clearVisibleRowOverridesAfterDelay()
@refs.verticalScrollbar.getDOMNode().scrollTop -= event.wheelDeltaY
@refs.horizontalScrollbar.getDOMNode().scrollLeft -= event.wheelDeltaX
event.preventDefault()
onMouseDown: (event) ->