From 62e31657ca7a13e03e900137497269498219fb02 Mon Sep 17 00:00:00 2001 From: Joonsoo Jeon Date: Fri, 3 May 2013 17:51:13 +0900 Subject: [PATCH 1/2] markClean and isClean added into UndoManager --- lib/ace/undomanager.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/ace/undomanager.js b/lib/ace/undomanager.js index 4f7626fe..b99850c1 100644 --- a/lib/ace/undomanager.js +++ b/lib/ace/undomanager.js @@ -65,6 +65,13 @@ var UndoManager = function() { this.$doc = options.args[1]; this.$undoStack.push(deltas); this.$redoStack = []; + + if (this.dirtyCounter < 0) { + // The user has made a change after undoing past the last clean state. + // We can never get back to a clean state now until markClean() is called. + this.dirtyCounter = NaN; + } + this.dirtyCounter++; }; /** @@ -82,6 +89,8 @@ var UndoManager = function() { this.$doc.undoChanges(deltas, dontSelect); this.$redoStack.push(deltas); } + + this.dirtyCounter--; return undoSelectionRange; }; @@ -99,6 +108,8 @@ var UndoManager = function() { this.$doc.redoChanges(deltas, dontSelect); this.$undoStack.push(deltas); } + + this.dirtyCounter++; return redoSelectionRange; }; @@ -109,6 +120,7 @@ var UndoManager = function() { this.reset = function() { this.$undoStack = []; this.$redoStack = []; + this.dirtyCounter = 0; }; /** @@ -129,6 +141,23 @@ var UndoManager = function() { return this.$redoStack.length > 0; }; + /** + * + * Marks the current status clean + **/ + this.markClean = function() { + this.dirtyCounter = 0; + }; + + /** + * + * Returns if the current status is clean + * @returns {Boolean} + **/ + this.isClean = function() { + return this.dirtyCounter === 0; + }; + }).call(UndoManager.prototype); exports.UndoManager = UndoManager; From 2baffd32560d4c0a23459b9b366de827b29e9dfa Mon Sep 17 00:00:00 2001 From: Joonsoo Jeon Date: Mon, 6 May 2013 10:25:12 +0900 Subject: [PATCH 2/2] indentation fixed --- lib/ace/undomanager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ace/undomanager.js b/lib/ace/undomanager.js index b99850c1..599e9158 100644 --- a/lib/ace/undomanager.js +++ b/lib/ace/undomanager.js @@ -67,9 +67,9 @@ var UndoManager = function() { this.$redoStack = []; if (this.dirtyCounter < 0) { - // The user has made a change after undoing past the last clean state. - // We can never get back to a clean state now until markClean() is called. - this.dirtyCounter = NaN; + // The user has made a change after undoing past the last clean state. + // We can never get back to a clean state now until markClean() is called. + this.dirtyCounter = NaN; } this.dirtyCounter++; };