From 23d9f6e41fba26795db2de6a4105c8674ceb4db7 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Thu, 16 Jan 2014 08:33:46 -0800 Subject: [PATCH] Use actual indentation length when setting indentation for row. Closes #1293 --- spec/editor-spec.coffee | 9 +++++++++ src/editor.coffee | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 96bca8bf3..ecd6e6d7a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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) diff --git a/src/editor.coffee b/src/editor.coffee index 40615a4bf..698030e90 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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. #