markClean and isClean added into UndoManager

This commit is contained in:
Joonsoo Jeon 2013-05-03 17:51:13 +09:00
commit 62e31657ca

View file

@ -65,6 +65,13 @@ var UndoManager = function() {
this.$doc = options.args[1]; this.$doc = options.args[1];
this.$undoStack.push(deltas); this.$undoStack.push(deltas);
this.$redoStack = []; 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.$doc.undoChanges(deltas, dontSelect);
this.$redoStack.push(deltas); this.$redoStack.push(deltas);
} }
this.dirtyCounter--;
return undoSelectionRange; return undoSelectionRange;
}; };
@ -99,6 +108,8 @@ var UndoManager = function() {
this.$doc.redoChanges(deltas, dontSelect); this.$doc.redoChanges(deltas, dontSelect);
this.$undoStack.push(deltas); this.$undoStack.push(deltas);
} }
this.dirtyCounter++;
return redoSelectionRange; return redoSelectionRange;
}; };
@ -109,6 +120,7 @@ var UndoManager = function() {
this.reset = function() { this.reset = function() {
this.$undoStack = []; this.$undoStack = [];
this.$redoStack = []; this.$redoStack = [];
this.dirtyCounter = 0;
}; };
/** /**
@ -129,6 +141,23 @@ var UndoManager = function() {
return this.$redoStack.length > 0; 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); }).call(UndoManager.prototype);
exports.UndoManager = UndoManager; exports.UndoManager = UndoManager;