Use actual indentation length when setting indentation for row.

Closes #1293
This commit is contained in:
probablycorey
2014-01-16 08:33:46 -08:00
parent b9dcb569b1
commit 23d9f6e41f
2 changed files with 11 additions and 3 deletions

View File

@@ -2722,6 +2722,15 @@ describe "Editor", ->
editor.moveCursorLeft()
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
describe ".setIndentationForBufferRow", ->
describe "when the editor uses soft tabs but the row has hard tabs", ->
it "only replaces whitespace charachters", ->
editor.setSoftWrap(true)
editor.setText(" 1\n 2")
editor.setCursorBufferPosition([0, 0])
editor.setIndentationForBufferRow(0, 2)
expect(editor.getText()).toBe(" 1\n 2")
describe "when the editor's grammar has an injection selector", ->
beforeEach ->
atom.packages.activatePackage('language-text', sync: true)

View File

@@ -269,10 +269,9 @@ class Editor extends Model
# * newLevel:
# A {Number} indicating the new indentation level.
setIndentationForBufferRow: (bufferRow, newLevel) ->
currentLevel = @indentationForBufferRow(bufferRow)
currentIndentString = @buildIndentString(currentLevel)
currentIndentLength = @lineForBufferRow(bufferRow).match(/^\s*/)[0].length
newIndentString = @buildIndentString(newLevel)
@buffer.change([[bufferRow, 0], [bufferRow, currentIndentString.length]], newIndentString)
@buffer.change([[bufferRow, 0], [bufferRow, currentIndentLength]], newIndentString)
# Public: Returns the indentation level of the given line of text.
#