From c34db290e408d5c50df154ecb6de03aaeb24c0da Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 7 May 2013 15:58:25 -0700 Subject: [PATCH] Only indent the line following a '\n' not the line preceding it --- spec/app/edit-session-spec.coffee | 12 ++++++++++++ src/app/selection.coffee | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index ae2d92406..8014a0bbc 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -2369,6 +2369,18 @@ describe "EditSession", -> editSession.insertText('\n') expect(editSession.indentationForBufferRow(6)).toBe editSession.indentationForBufferRow(5) + it "does not indent the line preceding the newline", -> + config.set("editor.autoIndent", true) + editSession.setCursorBufferPosition([2, 0]) + editSession.insertText(' var this-line-should-be-indented-more\n') + expect(editSession.indentationForBufferRow(1)).toBe 1 + + config.set("editor.autoIndent", true) + editSession.setCursorBufferPosition([2, Infinity]) + editSession.insertText('\n') + expect(editSession.indentationForBufferRow(1)).toBe 1 + expect(editSession.indentationForBufferRow(2)).toBe 1 + describe "when inserted text matches a decrease indent pattern", -> describe "when the preceding line matches an increase indent pattern", -> it "decreases the indentation of the line to match that of the preceding line", -> diff --git a/src/app/selection.coffee b/src/app/selection.coffee index a69866ca8..d5d6223d0 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -273,8 +273,10 @@ class Selection else @cursor.setBufferPosition(newBufferRange.end, skipAtomicTokens: true) if wasReversed - if options.autoIndent or (options.autoIndentNewline and text == '\n') + if options.autoIndent @editSession.autoIndentBufferRow(row) for row in newBufferRange.getRows() + else if options.autoIndentNewline and text == '\n' + @editSession.autoIndentBufferRow(newBufferRange.end.row) else if options.autoDecreaseIndent and /\S/.test text @editSession.autoDecreaseIndentForRow(newBufferRange.start.row)