diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 4a2cce174..704d062fb 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1616,6 +1616,13 @@ describe "Editor", -> expect(editor.lineForBufferRow(1)).toBe ' ' expect(editor.lineForBufferRow(2)).toBe '}' + describe "when a new line is appended before a closing tag (e.g. by pressing enter before a selection)", -> + it "moves the line down and keeps the indentation level the same when editor.autoIndent is true", -> + atom.config.set('editor.autoIndent', true) + editor.setCursorBufferPosition([9,2]) + editor.insertNewline() + expect(editor.lineForBufferRow(10)).toBe ' };' + describe ".backspace()", -> describe "when there is a single cursor", -> changeScreenRangeHandler = null diff --git a/src/selection.coffee b/src/selection.coffee index e3eeb15a3..0c3161837 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -305,7 +305,10 @@ class Selection extends Model if options.autoIndent @editor.autoIndentBufferRow(row) for row in newBufferRange.getRows() else if options.autoIndentNewline and text == '\n' + currentIndentation = @editor.indentationForBufferRow(newBufferRange.start.row) @editor.autoIndentBufferRow(newBufferRange.end.row, preserveLeadingWhitespace: true) + if @editor.indentationForBufferRow(newBufferRange.end.row) < currentIndentation + @editor.setIndentationForBufferRow(newBufferRange.end.row, currentIndentation) else if options.autoDecreaseIndent and /\S/.test text @editor.autoDecreaseIndentForBufferRow(newBufferRange.start.row)