Correctly autoindent single newline in Selection#insertText

This commit is contained in:
Michelle Tilley
2016-04-15 21:23:00 -07:00
parent 8ece1ee909
commit e41b9f00fb
2 changed files with 6 additions and 1 deletions

View File

@@ -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 " "

View File

@@ -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)