Just wrapping transformation/transformations array on the undo/redo stacks
if(this._transactionInProgress) {
this._transactionStack.push(transformation);
} else {
if(this._transactionInProgress) {
this._transactionStack.push(transformation);
} else {
- this.undoStack.push(transformation);
+ this.undoStack.push(new Transaction([transformation]));
}
}
if(!this._undoInProgress && this._transformationLevel === 1) {
}
}
if(!this._undoInProgress && this._transformationLevel === 1) {
- var transformationObject = this.undoStack.pop(),
+ var transaction = this.undoStack.pop(),
doc = this,
transformations, stopAt;
doc = this,
transformations, stopAt;
- if(transformationObject) {
this._undoInProgress = true;
this._undoInProgress = true;
- if(_.isArray(transformationObject)) {
- // We will modify this array in a minute so make sure we work on a copy.
- transformations = transformationObject.slice(0);
- } else {
- // Lets normalize single transformation to a transaction containing one transformation.
- transformations = [transformationObject];
- }
+ // We will modify this array in a minute so make sure we work on a copy.
+ transformations = transaction.transformations.slice(0);
if(transformations.length > 1) {
// In case of real transactions we don't want to run undo on all of transformations if we don't have to.
if(transformations.length > 1) {
// In case of real transactions we don't want to run undo on all of transformations if we don't have to.
});
this._undoInProgress = false;
});
this._undoInProgress = false;
- this.redoStack.push(transformationObject);
+ this.redoStack.push(transaction);
- var transformationObject = this.redoStack.pop(),
- transformations;
- if(transformationObject) {
+ var transaction = this.redoStack.pop();
+ if(transaction) {
this._transformationLevel++;
this._transformationLevel++;
- transformations = _.isArray(transformationObject) ? transformationObject : [transformationObject];
- transformations.forEach(function(t) {
+ transaction.transformations.forEach(function(t) {
t.run({beUndoable: true});
});
this._transformationLevel--;
t.run({beUndoable: true});
});
this._transformationLevel--;
- this.undoStack.push(transformationObject);
+ this.undoStack.push(transaction);
}
this._transactionInProgress = false;
if(this._transactionStack.length) {
}
this._transactionInProgress = false;
if(this._transactionStack.length) {
- this.undoStack.push(this._transactionStack);
+ this.undoStack.push(new Transaction(this._transactionStack));
this._transactionStack = [];
}
},
this._transactionStack = [];
}
},
+var Transaction = function(transformations) {
+ this.transformations = transformations || [];
+};
+
return {
documentFromXML: function(xml) {
return {
documentFromXML: function(xml) {