From 574db72780721cd170bc75b663fd3d350262d459 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 4 May 2010 11:55:46 +0200 Subject: [PATCH] fix undo manger bug --- src/ace/Document.js | 11 ++++++----- src/test/DocumentTest.js | 10 ++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/ace/Document.js b/src/ace/Document.js index 93a68f3d..b0edb4eb 100644 --- a/src/ace/Document.js +++ b/src/ace/Document.js @@ -57,7 +57,8 @@ ace.Document = function(text, mode) { undoManager.setDocument(this); var self = this; this.$informUndoManager = ace.deferredCall(function() { - undoManager.notify(self.$deltas); + if (self.$deltas.length > 0) + undoManager.notify(self.$deltas); self.$deltas = []; }); } @@ -303,7 +304,7 @@ ace.Document = function(text, mode) { return end; }; - this.$insertLines = function(row, lines) { + this.$insertLines = function(row, lines, fromUndo) { if (lines.length == 0) return; @@ -311,7 +312,7 @@ ace.Document = function(text, mode) { args.push.apply(args, lines); this.lines.splice.apply(this.lines, args); - if (this.$undoManager) { + if (!fromUndo && this.$undoManager) { var nl = this.$getNewLineCharacter(); this.$deltas.push({ type: "insert", @@ -359,10 +360,10 @@ ace.Document = function(text, mode) { var lastLine = newLines[newLines.length - 1] + line.substring(position.column); this.lines[position.row] = firstLine; - this.$insertLines(position.row + 1, [lastLine]); + this.$insertLines(position.row + 1, [lastLine], fromUndo); 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 = { diff --git a/src/test/DocumentTest.js b/src/test/DocumentTest.js index 9dc1dd74..67814be0 100644 --- a/src/test/DocumentTest.js +++ b/src/test/DocumentTest.js @@ -134,35 +134,33 @@ var TextDocumentTest = new TestCase("TextDocumentTest", { editor.removeLines(); var step1 = doc.toString(); assertEquals("222\n333", step1); - // call normally async code now doc.$informUndoManager.call(); editor.removeLines(); var step2 = doc.toString(); assertEquals("333", step2); - // call normally async code now doc.$informUndoManager.call(); editor.removeLines(); var step3 = doc.toString(); assertEquals("", step3); - // call normally async code now doc.$informUndoManager.call(); undoManager.undo(); + doc.$informUndoManager.call(); assertEquals(step2, doc.toString()); undoManager.undo(); + doc.$informUndoManager.call(); assertEquals(step1, doc.toString()); undoManager.undo(); + doc.$informUndoManager.call(); assertEquals(initialText, doc.toString()); undoManager.undo(); + doc.$informUndoManager.call(); assertEquals(initialText, doc.toString()); - -// undoManager.redo(); -// assertEquals(removedText, doc.toString()); } }); \ No newline at end of file