From ab02d5f25fa18168ea5e6cde07441be64de9bfd9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 2 Apr 2014 18:55:38 -0600 Subject: [PATCH] Update the vertical scroll bar when scrollTop changes in the model --- spec/editor-component-spec.coffee | 10 ++++++++++ src/editor-component.coffee | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 51afa07bf..0d37088e9 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -82,6 +82,16 @@ describe "EditorComponent", -> expect(cursorNodes[0].offsetTop).toBe 6 * lineHeightInPixels expect(cursorNodes[0].offsetLeft).toBe 11 * charWidth + it "updates the scroll bar when the scrollTop is changed in the model", -> + node.style.height = 4.5 * lineHeightInPixels + 'px' + component.updateAllDimensions() + + scrollbarNode = node.querySelector('.vertical-scrollbar') + expect(scrollbarNode.scrollTop).toBe 0 + + editor.setScrollTop(10) + expect(scrollbarNode.scrollTop).toBe 10 + it "accounts for character widths when positioning cursors", -> atom.config.set('editor.fontFamily', 'sans-serif') editor.setCursorScreenPosition([0, 16]) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index d15b68eaf..9d67c646a 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -78,6 +78,10 @@ EditorCompont = React.createClass @getDOMNode().removeEventListener 'mousewheel', @onMousewheel componentDidUpdate: -> + # React offers a scrollTop property on element descriptors but it doesn't + # seem to work when reloading the editor while already scrolled down. + # Perhaps it's trying to assign it before the element inside is tall enough? + @refs.verticalScrollbar.getDOMNode().scrollTop = @props.editor.getScrollTop() @measureNewLines() observeEditor: ->