fix undo manger bug
This commit is contained in:
parent
4483598166
commit
574db72780
2 changed files with 10 additions and 11 deletions
|
|
@ -57,6 +57,7 @@ ace.Document = function(text, mode) {
|
||||||
undoManager.setDocument(this);
|
undoManager.setDocument(this);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$informUndoManager = ace.deferredCall(function() {
|
this.$informUndoManager = ace.deferredCall(function() {
|
||||||
|
if (self.$deltas.length > 0)
|
||||||
undoManager.notify(self.$deltas);
|
undoManager.notify(self.$deltas);
|
||||||
self.$deltas = [];
|
self.$deltas = [];
|
||||||
});
|
});
|
||||||
|
|
@ -303,7 +304,7 @@ ace.Document = function(text, mode) {
|
||||||
return end;
|
return end;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$insertLines = function(row, lines) {
|
this.$insertLines = function(row, lines, fromUndo) {
|
||||||
if (lines.length == 0)
|
if (lines.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -311,7 +312,7 @@ ace.Document = function(text, mode) {
|
||||||
args.push.apply(args, lines);
|
args.push.apply(args, lines);
|
||||||
this.lines.splice.apply(this.lines, args);
|
this.lines.splice.apply(this.lines, args);
|
||||||
|
|
||||||
if (this.$undoManager) {
|
if (!fromUndo && this.$undoManager) {
|
||||||
var nl = this.$getNewLineCharacter();
|
var nl = this.$getNewLineCharacter();
|
||||||
this.$deltas.push({
|
this.$deltas.push({
|
||||||
type: "insert",
|
type: "insert",
|
||||||
|
|
@ -359,10 +360,10 @@ ace.Document = function(text, mode) {
|
||||||
var lastLine = newLines[newLines.length - 1] + line.substring(position.column);
|
var lastLine = newLines[newLines.length - 1] + line.substring(position.column);
|
||||||
|
|
||||||
this.lines[position.row] = firstLine;
|
this.lines[position.row] = firstLine;
|
||||||
this.$insertLines(position.row + 1, [lastLine]);
|
this.$insertLines(position.row + 1, [lastLine], fromUndo);
|
||||||
|
|
||||||
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), fromUndo);
|
||||||
}
|
}
|
||||||
|
|
||||||
var end = {
|
var end = {
|
||||||
|
|
|
||||||
|
|
@ -134,35 +134,33 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
|
||||||
editor.removeLines();
|
editor.removeLines();
|
||||||
var step1 = doc.toString();
|
var step1 = doc.toString();
|
||||||
assertEquals("222\n333", step1);
|
assertEquals("222\n333", step1);
|
||||||
// call normally async code now
|
|
||||||
doc.$informUndoManager.call();
|
doc.$informUndoManager.call();
|
||||||
|
|
||||||
editor.removeLines();
|
editor.removeLines();
|
||||||
var step2 = doc.toString();
|
var step2 = doc.toString();
|
||||||
assertEquals("333", step2);
|
assertEquals("333", step2);
|
||||||
// call normally async code now
|
|
||||||
doc.$informUndoManager.call();
|
doc.$informUndoManager.call();
|
||||||
|
|
||||||
editor.removeLines();
|
editor.removeLines();
|
||||||
var step3 = doc.toString();
|
var step3 = doc.toString();
|
||||||
assertEquals("", step3);
|
assertEquals("", step3);
|
||||||
// call normally async code now
|
|
||||||
doc.$informUndoManager.call();
|
doc.$informUndoManager.call();
|
||||||
|
|
||||||
|
|
||||||
undoManager.undo();
|
undoManager.undo();
|
||||||
|
doc.$informUndoManager.call();
|
||||||
assertEquals(step2, doc.toString());
|
assertEquals(step2, doc.toString());
|
||||||
|
|
||||||
undoManager.undo();
|
undoManager.undo();
|
||||||
|
doc.$informUndoManager.call();
|
||||||
assertEquals(step1, doc.toString());
|
assertEquals(step1, doc.toString());
|
||||||
|
|
||||||
undoManager.undo();
|
undoManager.undo();
|
||||||
|
doc.$informUndoManager.call();
|
||||||
assertEquals(initialText, doc.toString());
|
assertEquals(initialText, doc.toString());
|
||||||
|
|
||||||
undoManager.undo();
|
undoManager.undo();
|
||||||
|
doc.$informUndoManager.call();
|
||||||
assertEquals(initialText, doc.toString());
|
assertEquals(initialText, doc.toString());
|
||||||
|
|
||||||
// undoManager.redo();
|
|
||||||
// assertEquals(removedText, doc.toString());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue