If inserting on a line that is longer than the suggested indent, preserve indent

This commit is contained in:
Nathan Sobo
2012-10-23 14:13:51 -06:00
parent 0e5c76b474
commit 7bd4e8801f
2 changed files with 9 additions and 2 deletions

View File

@@ -742,6 +742,13 @@ describe "EditSession", ->
describe "when the cursor's current column is greater than the suggested indent level", ->
it "preserves the current indent level, indenting all lines relative to it", ->
editSession.insertText('\n ')
editSession.insertText(text, normalizeIndent: true)
expect(editSession.lineForBufferRow(3)).toBe " while (true) {"
expect(editSession.lineForBufferRow(4)).toBe " foo();"
expect(editSession.lineForBufferRow(5)).toBe " }"
expect(editSession.lineForBufferRow(6)).toBe " bar();"
describe "if auto-indent is disabled", ->
it "always normalizes indented lines to the cursor's current indentation level", ->

View File

@@ -168,11 +168,11 @@ class Selection
normalizedLines.join('\n')
adjustIndentationForLine: (line, delta) ->
indentText = new Array(Math.abs(delta + 1)).join(' ')
indentText = new Array(Math.abs(delta) + 1).join(' ')
if delta > 0
indentText + line
else if delta < 0
line.replace(indentText, '')
line.replace(new RegExp("^#{indentText}"), '')
else
line