Handle 'editor:scroll-to-cursor' command

Add Editor::scrollToCursorPosition in the model layer
This commit is contained in:
Nathan Sobo
2014-04-22 16:43:32 -06:00
parent f53d489abb
commit e4639281f8
3 changed files with 18 additions and 1 deletions

View File

@@ -3028,3 +3028,17 @@ describe "Editor", ->
editor.setSoftTabs(false)
editor.normalizeTabsInBufferRange([[0, 0], [Infinity, Infinity]])
expect(editor.getText()).toBe ' '
describe ".scrollToCursorPosition()", ->
it "scrolls the last cursor into view", ->
editor.setCursorScreenPosition([8, 8])
editor.setLineHeight(10)
editor.setDefaultCharWidth(10)
editor.setHeight(50)
editor.setWidth(50)
expect(editor.getScrollTop()).toBe 0
expect(editor.getScrollLeft()).toBe 0
editor.scrollToCursorPosition()
expect(editor.getScrollBottom()).toBe (9 + editor.getVerticalScrollMargin()) * 10
expect(editor.getScrollRight()).toBe (9 + editor.getHorizontalScrollMargin()) * 10

View File

@@ -215,9 +215,9 @@ EditorComponent = React.createClass
'editor:join-lines': => editor.joinLines()
'editor:toggle-indent-guide': => atom.config.toggle('editor.showIndentGuide')
'editor:toggle-line-numbers': => atom.config.toggle('editor.showLineNumbers')
'editor:scroll-to-cursor': => editor.scrollToCursorPosition()
# 'core:page-down': => @pageDown()
# 'core:page-up': => @pageUp()
# 'editor:scroll-to-cursor': => @scrollToCursorPosition()
addCommandListeners: (listenersByCommandName) ->
{parentView} = @props

View File

@@ -1453,6 +1453,9 @@ class Editor extends Model
moveCursorToNextWordBoundary: ->
@moveCursors (cursor) -> cursor.moveToNextWordBoundary()
scrollToCursorPosition: ->
@getCursor().autoscroll()
moveCursors: (fn) ->
@movingCursors = true
@batchUpdates =>