Base first line delta on the cursor column, not the existing line's indent

This commit is contained in:
Nathan Sobo
2012-10-23 16:30:38 -06:00
parent 839d57d819
commit d1999b91ff
2 changed files with 9 additions and 5 deletions

View File

@@ -730,13 +730,14 @@ describe "EditSession", ->
describe "when the cursor's current column is less than the suggested indent level", ->
it "indents all lines relative to the suggested indent", ->
editSession.insertText('\n ')
editSession.insertText('\n xx')
editSession.setCursorBufferPosition([3, 1])
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();"
expect(editSession.lineForBufferRow(6)).toBe " bar();xx"
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", ->

View File

@@ -159,10 +159,12 @@ class Selection
textPrecedingCursor = @editSession.buffer.getTextInRange([[currentBufferRow, 0], [currentBufferRow, currentBufferColumn]])
insideExistingLine = textPrecedingCursor.match(/\S/)
if insideExistingLine or not @editSession.autoIndent
if insideExistingLine
desiredBase = @editSession.indentationForBufferRow(currentBufferRow)
else
else if @editSession.autoIndent
desiredBase = @editSession.suggestedIndentForBufferRow(currentBufferRow)
else
desiredBase = currentBufferColumn
currentBase = lines[0].match(/\s*/)[0].length
delta = desiredBase - currentBase
@@ -172,7 +174,8 @@ class Selection
if insideExistingLine
firstLineDelta = -line.length # remove all leading whitespace
else
firstLineDelta = delta - @editSession.indentationForBufferRow(currentBufferRow)
firstLineDelta = delta - currentBufferColumn
normalizedLines.push(@adjustIndentationForLine(line, firstLineDelta))
else
normalizedLines.push(@adjustIndentationForLine(line, delta))