mirror of
https://github.com/atom/atom.git
synced 2026-02-15 00:55:14 -05:00
Add autoscrolling with react editor view
Its implemented in the model to restrict touching of the DOM.
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user