fix bug in the document's insert method
This commit is contained in:
parent
0695b22125
commit
abd4734eca
3 changed files with 31 additions and 4 deletions
|
|
@ -358,11 +358,11 @@ ace.Document = function(text, mode) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var line = this.lines[position.row] || "";
|
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)
|
this.lines[position.row] = firstLine;
|
||||||
+ newLines[0];
|
this.$insertLines(position.row + 1, [lastLine]);
|
||||||
this.lines[position.row + 1] = newLines[newLines.length - 1]
|
|
||||||
+ line.substring(position.column);
|
|
||||||
|
|
||||||
if (newLines.length > 2) {
|
if (newLines.length > 2) {
|
||||||
this.$insertLines(position.row + 1, newLines.slice(1, -1));
|
this.$insertLines(position.row + 1, newLines.slice(1, -1));
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
call: function() {
|
||||||
|
this.cancel();
|
||||||
|
fcn();
|
||||||
|
},
|
||||||
|
|
||||||
cancel: function() {
|
cancel: function() {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = null;
|
timer = null;
|
||||||
|
|
|
||||||
|
|
@ -123,5 +123,27 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
|
||||||
end: {row: 2, column: 1}
|
end: {row: 2, column: 1}
|
||||||
}, ["4", "5", "6"].join("\n"));
|
}, ["4", "5", "6"].join("\n"));
|
||||||
assertEquals(["4", "5", "6"].join("\n"), doc.toString());
|
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());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue