Merge pull request #1410 from Joonsoo/master
Dirty check functionality added into UndoManager
This commit is contained in:
commit
8995ac1965
1 changed files with 29 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue