fix bug in the document's insert method

This commit is contained in:
Fabian Jakobs 2010-05-04 09:52:31 +02:00
commit abd4734eca
3 changed files with 31 additions and 4 deletions

View file

@ -358,11 +358,11 @@ ace.Document = function(text, mode) {
}
else {
var line = this.lines[position.row] || "";
var firstLine = line.substring(0, position.column) + newLines[0];
var lastLine = newLines[newLines.length - 1] + line.substring(position.column);
this.lines[position.row] = line.substring(0, position.column)
+ newLines[0];
this.lines[position.row + 1] = newLines[newLines.length - 1]
+ line.substring(position.column);
this.lines[position.row] = firstLine;
this.$insertLines(position.row + 1, [lastLine]);
if (newLines.length > 2) {
this.$insertLines(position.row + 1, newLines.slice(1, -1));

View file

@ -57,6 +57,11 @@
}
},
call: function() {
this.cancel();
fcn();
},
cancel: function() {
clearTimeout(timer);
timer = null;

View file

@ -123,5 +123,27 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
end: {row: 2, column: 1}
}, ["4", "5", "6"].join("\n"));
assertEquals(["4", "5", "6"].join("\n"), doc.toString());
},
"test: undo/redo for delete line" : function() {
var doc = new ace.Document(["111", "222", "333"]);
var undoManager = new ace.UndoManager();
doc.setUndoManager(undoManager);
var initialText = doc.toString();
var editor = new ace.Editor(new MockRenderer(), doc);
editor.removeLines();
var removedText = doc.toString();
// call normally async code now
doc.$informUndoManager.call();
undoManager.undo();
assertEquals(initialText, doc.toString());
undoManager.redo();
assertEquals(removedText, doc.toString());
}
});