Autoscroll cursors horizontally at the model layer

Still need to respect the horizontal scroll position in the editor view
This commit is contained in:
Nathan Sobo
2014-04-08 11:24:39 -06:00
parent 486a7937b5
commit 171631d20f
4 changed files with 62 additions and 12 deletions

View File

@@ -98,18 +98,26 @@ class Cursor
@marker.getHeadBufferPosition()
autoscroll: ->
scrollMarginInPixels = @editor.getVerticalScrollMargin() * @editor.getLineHeight()
{top, height} = @getPixelRect()
verticalScrollMarginInPixels = @editor.getVerticalScrollMargin() * @editor.getLineHeight()
horizontalScrollMarginInPixels = @editor.getHorizontalScrollMargin() * @editor.getDefaultCharWidth()
{top, left, height, width} = @getPixelRect()
bottom = top + height
desiredScrollTop = top - scrollMarginInPixels
desiredScrollBottom = bottom + scrollMarginInPixels
right = left + width
desiredScrollTop = top - verticalScrollMarginInPixels
desiredScrollBottom = bottom + verticalScrollMarginInPixels
desiredScrollLeft = left - horizontalScrollMarginInPixels
desiredScrollRight = right + horizontalScrollMarginInPixels
if desiredScrollTop < @editor.getScrollTop()
@editor.setScrollTop(desiredScrollTop)
else if desiredScrollBottom > @editor.getScrollBottom()
@editor.setScrollBottom(desiredScrollBottom)
if desiredScrollLeft < @editor.getScrollLeft()
@editor.setScrollLeft(desiredScrollLeft)
else if desiredScrollRight > @editor.getScrollRight()
@editor.setScrollRight(desiredScrollRight)
# Public: If the marker range is empty, the cursor is marked as being visible.
updateVisibility: ->
@setVisible(@marker.getBufferRange().isEmpty())