diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index c7d21989e..868226f5f 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2552,3 +2552,14 @@ describe "Editor", -> runs -> expect(editor.renderedLines.find('.line').text()).toBe 'hidden changes' + + describe "editor:scroll-to-cursor", -> + it "scrolls to and centers the editor on the cursor's position", -> + editor.attachToDom(heightInLines: 3) + editor.setCursorBufferPosition([1, 2]) + editor.scrollToBottom() + expect(editor.getFirstVisibleScreenRow()).not.toBe 0 + expect(editor.getLastVisibleScreenRow()).not.toBe 2 + editor.trigger('editor:scroll-to-cursor') + expect(editor.getFirstVisibleScreenRow()).toBe 0 + expect(editor.getLastVisibleScreenRow()).toBe 2 diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5ffdf3c45..1f66b8a42 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -164,6 +164,7 @@ class Editor extends View 'editor:toggle-indent-guide': => config.set('editor.showIndentGuide', !config.get('editor.showIndentGuide')) 'editor:save-debug-snapshot': @saveDebugSnapshot 'editor:toggle-line-numbers': => config.set('editor.showLineNumbers', !config.get('editor.showLineNumbers')) + 'editor:scroll-to-cursor': @scrollToCursorPosition documentation = {} for name, method of editorBindings @@ -523,6 +524,9 @@ class Editor extends View scrollToBottom: -> @scrollBottom(@screenLineCount() * @lineHeight) + scrollToCursorPosition: -> + @scrollToBufferPosition(@getCursorBufferPosition(), center: true) + scrollToBufferPosition: (bufferPosition, options) -> @scrollToPixelPosition(@pixelPositionForBufferPosition(bufferPosition), options) diff --git a/src/app/keymaps/editor.cson b/src/app/keymaps/editor.cson index 07568fc0b..f1af1b842 100644 --- a/src/app/keymaps/editor.cson +++ b/src/app/keymaps/editor.cson @@ -27,6 +27,7 @@ 'ctrl-meta-down': 'editor:move-line-down' 'meta-D': 'editor:duplicate-line' 'ctrl-J': 'editor:join-line' + 'meta-<': 'editor:scroll-to-cursor' '.editor.mini': 'enter': 'core:confirm',