Center around the cursor in Editor::scrollToCursorPosition by default

Fixes #3131
This commit is contained in:
Nathan Sobo
2014-08-04 11:57:55 -06:00
parent 6af69b0fc7
commit 7e45ffa4c3
4 changed files with 20 additions and 9 deletions

View File

@@ -95,8 +95,8 @@ class Cursor extends Model
getBufferPosition: ->
@marker.getHeadBufferPosition()
autoscroll: ->
@editor.scrollToScreenRange(@getScreenRange())
autoscroll: (options) ->
@editor.scrollToScreenRange(@getScreenRange(), options)
# Public: If the marker range is empty, the cursor is marked as being visible.
updateVisibility: ->

View File

@@ -641,9 +641,9 @@ class EditorView extends View
@scrollBottom(@editor.getScreenLineCount() * @lineHeight)
# Public: Scrolls the editor to the position of the most recently added
# cursor.
# cursor if it isn't current on screen.
#
# The editor is also centered.
# The editor is centered around the cursor's position if possible.
scrollToCursorPosition: ->
@scrollToBufferPosition(@editor.getCursorBufferPosition(), center: true)

View File

@@ -1588,8 +1588,14 @@ class Editor extends Model
moveCursorToBeginningOfPreviousParagraph: ->
@moveCursors (cursor) -> cursor.moveToBeginningOfPreviousParagraph()
scrollToCursorPosition: ->
@getCursor().autoscroll()
# Public: Scroll the editor to reveal the most recently added cursor if it is
# off-screen.
#
# options - An optional hash of options.
# :center - Center the editor around the cursor if possible. Defauls to
# true.
scrollToCursorPosition: (options) ->
@getCursor().autoscroll(center: options?.center ? true)
pageUp: ->
newScrollTop = @getScrollTop() - @getHeight()