From e4639281f8008e1bf5bc60290613798befc35749 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 22 Apr 2014 16:43:32 -0600 Subject: [PATCH] Handle 'editor:scroll-to-cursor' command Add Editor::scrollToCursorPosition in the model layer --- spec/editor-spec.coffee | 14 ++++++++++++++ src/editor-component.coffee | 2 +- src/editor.coffee | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index dffdd3374..ecbc30948 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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 diff --git a/src/editor-component.coffee b/src/editor-component.coffee index e6088e752..0e62d3a84 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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 diff --git a/src/editor.coffee b/src/editor.coffee index 9913a2250..95813163d 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -1453,6 +1453,9 @@ class Editor extends Model moveCursorToNextWordBoundary: -> @moveCursors (cursor) -> cursor.moveToNextWordBoundary() + scrollToCursorPosition: -> + @getCursor().autoscroll() + moveCursors: (fn) -> @movingCursors = true @batchUpdates =>