mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
Base first line delta on the cursor column, not the existing line's indent
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user