Update the vertical scroll bar when scrollTop changes in the model

This commit is contained in:
Nathan Sobo 2014-04-02 18:55:38 -06:00
parent e472d7b038
commit ab02d5f25f
2 changed files with 14 additions and 0 deletions

View File

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

View File

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