From e41b9f00fb7dc58299ab83aa111480960ab62ded Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Fri, 15 Apr 2016 21:23:00 -0700 Subject: [PATCH 1/2] Correctly autoindent single newline in Selection#insertText --- spec/selection-spec.coffee | 5 +++++ src/selection.coffee | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index 319e2d438..8830f4188 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -91,3 +91,8 @@ describe "Selection", -> expect(buffer.lineForRow(0)).toBe " " expect(buffer.lineForRow(1)).toBe " " expect(buffer.lineForRow(2)).toBe "" + + it "auto-indents if only a newline is inserted", -> + selection.setBufferRange [[2, 0], [3, 0]] + selection.insertText("\n", autoIndent: true) + expect(buffer.lineForRow(2)).toBe " " diff --git a/src/selection.coffee b/src/selection.coffee index e208ea55a..8d93d2fa1 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -378,7 +378,7 @@ class Selection extends Model indentAdjustment = @editor.indentLevelForLine(precedingText) - options.indentBasis @adjustIndent(remainingLines, indentAdjustment) - if options.autoIndent and NonWhitespaceRegExp.test(text) and not NonWhitespaceRegExp.test(precedingText) and remainingLines.length > 0 + if options.autoIndent and (text is '\n' or NonWhitespaceRegExp.test(text)) and not NonWhitespaceRegExp.test(precedingText) and remainingLines.length > 0 autoIndentFirstLine = true firstLine = precedingText + firstInsertedLine desiredIndentLevel = @editor.languageMode.suggestedIndentForLineAtBufferRow(oldBufferRange.start.row, firstLine) From b2aad098e118e6d1ba637a6088b1c831e5c0e402 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Sat, 16 Apr 2016 11:14:21 -0700 Subject: [PATCH 2/2] Correctly autoindent \r\n in Selection#insertText --- spec/selection-spec.coffee | 5 +++++ src/selection.coffee | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/selection-spec.coffee b/spec/selection-spec.coffee index 8830f4188..18095d6f8 100644 --- a/spec/selection-spec.coffee +++ b/spec/selection-spec.coffee @@ -96,3 +96,8 @@ describe "Selection", -> selection.setBufferRange [[2, 0], [3, 0]] selection.insertText("\n", autoIndent: true) expect(buffer.lineForRow(2)).toBe " " + + it "auto-indents if only a carriage return + newline is inserted", -> + selection.setBufferRange [[2, 0], [3, 0]] + selection.insertText("\r\n", autoIndent: true) + expect(buffer.lineForRow(2)).toBe " " diff --git a/src/selection.coffee b/src/selection.coffee index 8d93d2fa1..2937baaee 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -378,7 +378,8 @@ class Selection extends Model indentAdjustment = @editor.indentLevelForLine(precedingText) - options.indentBasis @adjustIndent(remainingLines, indentAdjustment) - if options.autoIndent and (text is '\n' or NonWhitespaceRegExp.test(text)) and not NonWhitespaceRegExp.test(precedingText) and remainingLines.length > 0 + textIsAutoIndentable = text is '\n' or text is '\r\n' or NonWhitespaceRegExp.test(text) + if options.autoIndent and textIsAutoIndentable and not NonWhitespaceRegExp.test(precedingText) and remainingLines.length > 0 autoIndentFirstLine = true firstLine = precedingText + firstInsertedLine desiredIndentLevel = @editor.languageMode.suggestedIndentForLineAtBufferRow(oldBufferRange.start.row, firstLine)