Move cursor to end of line when on first row

This line may be indented now so move the cursor to the
end of the indentation.
This commit is contained in:
Kevin Sawicki
2014-04-04 10:22:09 -07:00
parent e464c4f047
commit 6e422d5428
2 changed files with 14 additions and 1 deletions

View File

@@ -1426,6 +1426,15 @@ describe "Editor", ->
it "indents the new line to the same indent level as the current line when editor.autoIndent is true", ->
atom.config.set('editor.autoIndent', true)
editor.setText(' var test')
editor.setCursorBufferPosition([0,2])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [0,2]
expect(editor.lineForBufferRow(0)).toBe ' '
expect(editor.lineForBufferRow(1)).toBe ' var test'
editor.setText('\n var test')
editor.setCursorBufferPosition([1,2])
editor.insertNewlineAbove()

View File

@@ -625,11 +625,15 @@ class Editor extends Model
bufferRow = @getCursorBufferPosition().row
indentLevel = @indentationForBufferRow(bufferRow)
onFirstLine = bufferRow is 0
@moveCursorToBeginningOfLine()
@moveCursorLeft()
@insertNewline()
@setIndentationForBufferRow(bufferRow, indentLevel) if @shouldAutoIndent()
@moveCursorUp() if onFirstLine
if onFirstLine
@moveCursorUp()
@moveCursorToEndOfLine()
# Indent all lines intersecting selections. See {Selection::indent} for more
# information.