diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 5169c0abe..799d2ad21 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -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", -> diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 23a2ebdb5..67298b380 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -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))