With autoIndent disabled, don't use suggested first line indent when normalizing

Also, when some lines are *less* indented than the first line, it might not be possible to outdent them as far as they originally were relative to the first line, so we do as much as possible.
This commit is contained in:
Nathan Sobo
2012-10-23 14:27:26 -06:00
parent 7bd4e8801f
commit 3b18c6a42d
2 changed files with 25 additions and 10 deletions

View File

@@ -151,16 +151,20 @@ class Selection
normalizeIndent: (text) ->
return text unless /\n/.test(text)
currentBufferRow = @cursor.getBufferRow()
lines = text.split('\n')
normalizedLines = []
desiredBase = @editSession.suggestedIndentForBufferRow(@cursor.getBufferRow())
if @editSession.autoIndent
desiredBase = @editSession.suggestedIndentForBufferRow(currentBufferRow)
else
desiredBase = @editSession.indentationForBufferRow(currentBufferRow)
currentBase = lines[0].match(/\s*/)[0].length
delta = desiredBase - currentBase
for line, i in lines
if i == 0
firstLineDelta = delta - @editSession.indentationForBufferRow(@cursor.getBufferRow())
firstLineDelta = delta - @editSession.indentationForBufferRow(currentBufferRow)
normalizedLines.push(@adjustIndentationForLine(line, firstLineDelta))
else
normalizedLines.push(@adjustIndentationForLine(line, delta))
@@ -169,10 +173,11 @@ class Selection
adjustIndentationForLine: (line, delta) ->
indentText = new Array(Math.abs(delta) + 1).join(' ')
if delta > 0
indentText + line
new Array(delta + 1).join(' ') + line
else if delta < 0
line.replace(new RegExp("^#{indentText}"), '')
line.replace(new RegExp("^ {0,#{Math.abs(delta)}}"), '')
else
line