mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user