mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
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:
parent
cd6b54a4e8
commit
e9346fdb60
|
@ -251,6 +251,18 @@ ve.dm.Surface.prototype.getFragment = function ( range, noAutoSelect ) {
|
||||||
return new ve.dm.SurfaceFragment( this, range || this.selection, 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.
|
* 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++ ) {
|
for ( i = 0, len = transactions.length; i < len; i++ ) {
|
||||||
if ( !transactions[i].isNoOp() ) {
|
if ( !transactions[i].isNoOp() ) {
|
||||||
this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
|
this.truncateUndoStack();
|
||||||
this.undoIndex = 0;
|
|
||||||
this.smallStack.push( transactions[i] );
|
this.smallStack.push( transactions[i] );
|
||||||
this.completeHistory.push( {
|
this.completeHistory.push( {
|
||||||
'undo': false,
|
'undo': false,
|
||||||
|
|
Loading…
Reference in a new issue