Use current indent level for newline above

Previously Editor::insertNewlineAbove would put the cursor
at position 0 if there were empty lines above the current line
regarding of the indent level of the cursor's current line.

Now the indent level of the current line is always used for the newline
above when the editor.autoIndent config is enabled.
This commit is contained in:
Kevin Sawicki
2014-04-04 10:02:24 -07:00
parent 4610c4446a
commit e464c4f047
2 changed files with 15 additions and 1 deletions

View File

@@ -1424,6 +1424,17 @@ describe "Editor", ->
editor.undo()
expect(editor.getCursorBufferPosition()).toEqual [3,4]
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('\n var test')
editor.setCursorBufferPosition([1,2])
editor.insertNewlineAbove()
expect(editor.getCursorBufferPosition()).toEqual [1,2]
expect(editor.lineForBufferRow(0)).toBe ''
expect(editor.lineForBufferRow(1)).toBe ' '
expect(editor.lineForBufferRow(2)).toBe ' var test'
describe ".backspace()", ->
describe "when there is a single cursor", ->
changeScreenRangeHandler = null

View File

@@ -622,10 +622,13 @@ class Editor extends Model
# Public: For each cursor, insert a newline at the end of the preceding line.
insertNewlineAbove: ->
@transact =>
onFirstLine = @getCursorBufferPosition().row is 0
bufferRow = @getCursorBufferPosition().row
indentLevel = @indentationForBufferRow(bufferRow)
onFirstLine = bufferRow is 0
@moveCursorToBeginningOfLine()
@moveCursorLeft()
@insertNewline()
@setIndentationForBufferRow(bufferRow, indentLevel) if @shouldAutoIndent()
@moveCursorUp() if onFirstLine
# Indent all lines intersecting selections. See {Selection::indent} for more