Using editor transact


#1

I am using following piece of code in my package. My feeling is that since i am only changing the editor content in one line ie. setText, there is no need to use editor.transact.

var cursor_position = editor.getCursorBufferPosition();
var line_text = editor.lineForBufferRow(cursor_position.row);
var line_length = editor.lineLengthForBufferRow(cursor_position.row);
var spaces = Math.max(0, this.editor_settings.indentation_spaces);
var regex = /^(\s*\*)\s*$/;
line_text = line_text.replace(regex, ('$1\n$1' + this.repeat(' ', spaces)));
var range = [[cursor_position.row, 0], [cursor_position.row, line_length]];
editor.setTextInBufferRange(range, line_text);

So is my reasoning wrong? If so what is the right way to do it?


#2

Since you are only doing one change, it is my understanding that this will be only one undo action. Though, if I recall correctly, there are single methods that could potentially create multiple undo actions … TextBuffer.replace perhaps.