From 1afdd62a5d20f62d3fcafe5e0f17a310441dba38 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 11 Apr 2014 10:05:56 -0700 Subject: [PATCH] Only alter indentation when it is too low Previously insert newline above would use the current line's indent level which could be the less than the proper level if the newline should be further indented based on the increase indent pattern being used. --- spec/editor-spec.coffee | 11 ++++++++++- src/editor.coffee | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 247f83e0f..aca279e2a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1424,7 +1424,7 @@ 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", -> + it "indents the new line to the correct level when editor.autoIndent is true", -> atom.config.set('editor.autoIndent', true) editor.setText(' var test') @@ -1444,6 +1444,15 @@ describe "Editor", -> expect(editor.lineForBufferRow(1)).toBe ' ' expect(editor.lineForBufferRow(2)).toBe ' var test' + editor.setText('function() {\n}') + editor.setCursorBufferPosition([1,1]) + editor.insertNewlineAbove() + + expect(editor.getCursorBufferPosition()).toEqual [1,2] + expect(editor.lineForBufferRow(0)).toBe 'function() {' + expect(editor.lineForBufferRow(1)).toBe ' ' + expect(editor.lineForBufferRow(2)).toBe '}' + describe ".backspace()", -> describe "when there is a single cursor", -> changeScreenRangeHandler = null diff --git a/src/editor.coffee b/src/editor.coffee index 825c9c400..aa492db18 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -630,7 +630,9 @@ class Editor extends Model @moveCursorToBeginningOfLine() @moveCursorLeft() @insertNewline() - @setIndentationForBufferRow(bufferRow, indentLevel) if @shouldAutoIndent() + + if @shouldAutoIndent() and @indentationForBufferRow(bufferRow) < indentLevel + @setIndentationForBufferRow(bufferRow, indentLevel) if onFirstLine @moveCursorUp()