Implement ve.dm.Surface#truncateUndoStack

ve.dm.Surface.js
* Allow manual truncation of the undo stack to prevent redoing something
  that's been undone

Change-Id: I17534d6724fc2b325152cb2f665c6816f44232c1
This commit is contained in:
Trevor Parscal 2013-04-29 13:57:32 -07:00 committed by Gerrit Code Review
parent cd6b54a4e8
commit e9346fdb60

View file

@ -251,6 +251,18 @@ ve.dm.Surface.prototype.getFragment = function ( range, noAutoSelect ) {
return new ve.dm.SurfaceFragment( this, range || this.selection, noAutoSelect );
};
/**
* Prevent future states from being redone.
*
* @method
* @emits history
*/
ve.dm.Surface.prototype.truncateUndoStack = function() {
this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
this.undoIndex = 0;
this.emit( 'history' );
};
/**
* Apply a transactions and selection changes to the document.
*
@ -284,8 +296,7 @@ ve.dm.Surface.prototype.change = function ( transactions, selection ) {
}
for ( i = 0, len = transactions.length; i < len; i++ ) {
if ( !transactions[i].isNoOp() ) {
this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
this.undoIndex = 0;
this.truncateUndoStack();
this.smallStack.push( transactions[i] );
this.completeHistory.push( {
'undo': false,