Add autoscrolling with react editor view

Its implemented in the model to restrict touching of the DOM.
This commit is contained in:
Nathan Sobo
2014-04-02 18:32:19 -06:00
parent ba83b0ede0
commit e472d7b038
4 changed files with 61 additions and 4 deletions

View File

@@ -27,7 +27,12 @@ class Cursor
{textChanged} = e
return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)
# Supports old editor view
@needsAutoscroll ?= @isLastCursor() and !textChanged
# Supports react editor view
@autoscroll() if @needsAutoscroll
@goalColumn = null
movedEvent =
@@ -92,6 +97,19 @@ class Cursor
getBufferPosition: ->
@marker.getHeadBufferPosition()
autoscroll: ->
scrollMarginInPixels = @editor.getVerticalScrollMargin() * @editor.getLineHeight()
{top, height} = @getPixelRect()
bottom = top + height
desiredScrollTop = top - scrollMarginInPixels
desiredScrollBottom = bottom + scrollMarginInPixels
if desiredScrollTop < @editor.getScrollTop()
@editor.setScrollTop(desiredScrollTop)
else if desiredScrollBottom > @editor.getScrollBottom()
@editor.setScrollBottom(desiredScrollBottom)
# Public: If the marker range is empty, the cursor is marked as being visible.
updateVisibility: ->
@setVisible(@marker.getBufferRange().isEmpty())