Bind meta-< to scroll to cursor location

This commit is contained in:
Kevin Sawicki
2013-04-09 14:33:36 -07:00
parent 8bfc3e473e
commit 53c3fa8ac8
3 changed files with 16 additions and 0 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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',