Added clearing method

This commit is contained in:
Marcin Lawrowski 2014-07-26 16:38:48 +02:00
parent 432c5ed9e5
commit cacc9dc2c9
3 changed files with 47 additions and 0 deletions

View File

@ -733,6 +733,15 @@
*/ */
removeUndoType: function (type) { removeUndoType: function (type) {
manipulateUndoType(2, type, undefined, this.undoTypes); manipulateUndoType(2, type, undefined, this.undoTypes);
},
/**
* Removes all actions from the stack.
* @return {undefined}
*/
clear: function() {
this.stack.reset();
this.stack.pointer = -1;
} }
}); });

View File

@ -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. 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`: Methods you can call on the object `Backbone.UndoManager`:

View File

@ -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") 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 * Async tests for magic condensation
*/ */