From cfdea7e73f9494d4c3315c3611914e7dabb82191 Mon Sep 17 00:00:00 2001 From: David Graham & Nathan Sobo Date: Tue, 8 Apr 2014 14:20:19 -0600 Subject: [PATCH] Update the scrollLeft of the model when the horizontal scrollbar changes --- spec/editor-component-spec.coffee | 10 ++++++++++ src/editor-component.coffee | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index a3ddf3949..95a3867dc 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -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 diff --git a/src/editor-component.coffee b/src/editor-component.coffee index e232c7ceb..33976ef2e 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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) ->