Fixing problems of undoAll / redoAll

Fixing the severe problems caused by mixing undoAll / redoAll with
regular undo / redo calls
This commit is contained in:
Oliver Sartun 2014-09-17 16:13:17 +02:00
parent a8e3ded102
commit cb50f8da09

View File

@ -266,20 +266,19 @@
} }
stack.isCurrentlyUndoRedoing = true; stack.isCurrentlyUndoRedoing = true;
var action, actions, isUndo = which === "undo"; var action, actions, isUndo = which === "undo";
if (isUndo) {
action = stack.at(stack.pointer);
stack.pointer--;
} else {
stack.pointer++;
action = stack.at(stack.pointer);
}
if (everything) { if (everything) {
actions = _.clone(stack.models); // Undo / Redo all steps until you reach the stack's beginning / end
actions = isUndo && stack.pointer === stack.length - 1 || // If at the stack's end calling undo
!isUndo && stack.pointer === -1 ? // or at the stack's beginning calling redo
_.clone(stack.models) : // => Take all the models. Otherwise:
core_slice.apply(stack.models, isUndo ? [0, stack.pointer] : [stack.pointer, stack.length - 1]);
} else { } else {
// Undo / Redo only one step
action = stack.at(isUndo ? stack.pointer : stack.pointer + 1);
actions = magic ? stack.where({"magicFusionIndex": action.get("magicFusionIndex")}) : [action]; actions = magic ? stack.where({"magicFusionIndex": action.get("magicFusionIndex")}) : [action];
} }
stack.pointer += (isUndo ? -1 : 1) * (actions.length - 1); stack.pointer += (isUndo ? -1 : 1) * actions.length;
while (action = isUndo ? actions.pop() : actions.shift()) { while (action = isUndo ? actions.pop() : actions.shift()) {
// Here we're calling the Action's undo / redo method // Here we're calling the Action's undo / redo method
action[which](); action[which]();