Merge pull request #12 from marcin-lawrowski/feature/clearStack
Added clearing method Thanks for your contribution!
This commit is contained in:
commit
1dcb178788
@ -747,6 +747,15 @@
|
||||
*/
|
||||
removeUndoType: function (type) {
|
||||
manipulateUndoType(2, type, undefined, this.undoTypes);
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all actions from the stack.
|
||||
* @return {undefined}
|
||||
*/
|
||||
clear: function() {
|
||||
this.stack.reset();
|
||||
this.stack.pointer = -1;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -204,6 +204,10 @@ This changes an UndoType only on this specific undo manager and won't affect oth
|
||||
|
||||
This removes an UndoType only from from this specific undo manager. See the UndoTypes-API for a more thorough documentation on this function.
|
||||
|
||||
#### clear `undoManager.clear()`
|
||||
|
||||
This removes all actions from the stack of actions.
|
||||
|
||||
***
|
||||
|
||||
Methods you can call on the object `Backbone.UndoManager`:
|
||||
|
@ -272,6 +272,40 @@ test("Merging UndoManagers", 2, function () {
|
||||
deepEqual(main.stack.at(1).toJSON().after, {"t": 2}, "The main undomanager can still write on its own stack")
|
||||
})
|
||||
|
||||
test("Clearing all actions", function () {
|
||||
var model = new Backbone.Model({
|
||||
"t": 1
|
||||
});
|
||||
|
||||
var UndoManager = new Backbone.UndoManager({
|
||||
track: true,
|
||||
register: model
|
||||
});
|
||||
|
||||
model.set("t", 2);
|
||||
model.set("t", 3);
|
||||
model.set("t", 4);
|
||||
|
||||
UndoManager.clear();
|
||||
|
||||
UndoManager.undo();
|
||||
|
||||
deepEqual(model.toJSON(), {"t": 4}, "Clearing actions before undoing was successful");
|
||||
|
||||
model.set("t", 2);
|
||||
model.set("t", 3);
|
||||
model.set("t", 4);
|
||||
|
||||
UndoManager.undo();
|
||||
UndoManager.undo();
|
||||
|
||||
UndoManager.clear();
|
||||
|
||||
UndoManager.redo();
|
||||
|
||||
deepEqual(model.toJSON(), {"t": 2}, "Clearing actions before redoing was successful");
|
||||
})
|
||||
|
||||
/**
|
||||
* Async tests for magic condensation
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user