Only indent the line following a '\n' not the line preceding it

This commit is contained in:
probablycorey
2013-05-07 15:58:25 -07:00
parent 9d2b7875b9
commit c34db290e4
2 changed files with 15 additions and 1 deletions

View File

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

View File

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