Merge "Only undo on MWMetaDialog close if small stack is non-empty"

This commit is contained in:
jenkins-bot 2013-06-18 19:34:15 +00:00 committed by Gerrit Code Review
commit 8e4177c960
3 changed files with 30 additions and 4 deletions

View file

@ -411,10 +411,11 @@ ve.dm.Surface.prototype.change = function ( transactions, selection ) {
* @method
* @param {ve.Range} selection New selection range
* @emits history
* @returns {boolean} A breakpoint was added
*/
ve.dm.Surface.prototype.breakpoint = function ( selection ) {
if ( !this.enabled ) {
return;
return false;
}
if ( this.smallStack.length > 0 ) {
this.bigStack.push( {
@ -423,7 +424,9 @@ ve.dm.Surface.prototype.breakpoint = function ( selection ) {
} );
this.smallStack = [];
this.emit( 'history' );
return true;
}
return false;
};
/**

View file

@ -57,3 +57,26 @@ QUnit.test( 'change', 3, function ( assert ) {
surface.change( tx, new ve.Range( 2, 2 ) );
assert.deepEqual( events, { 'transact': 2, 'select': 2, 'change': 3 } );
} );
QUnit.test( 'breakpoint', 7, function ( assert ) {
var surface = new ve.dm.SurfaceStub(),
tx = new ve.dm.Transaction.newFromInsertion( surface.dm, 1, ['x'] ),
selection = new ve.Range( 1, 1 );
assert.equal( surface.breakpoint(), false, 'Returns false if no transactions applied' );
surface.change( tx, selection );
assert.deepEqual( surface.bigStack, [], 'Big stack data matches before breakpoint' );
assert.deepEqual( surface.smallStack, [tx], 'Small stack data matches before breakpoint' );
assert.equal( surface.breakpoint(), true, 'Returns true after transaction applied' );
assert.equal( surface.breakpoint(), false, 'Returns false if no transactions applied since last breakpoint' );
assert.deepEqual( surface.bigStack, [ {
'stack': [tx],
'selection': selection
} ],
'Big stack data matches after breakpoint'
);
assert.deepEqual( surface.smallStack, [], 'Small stack data matches after breakpoint' );
} );

View file

@ -178,7 +178,7 @@ ve.ui.MWMetaDialog.prototype.onOpen = function () {
* @param {string} action Action that caused the window to be closed
*/
ve.ui.MWMetaDialog.prototype.onClose = function ( action ) {
var newDefaultSortKeyItem, newDefaultSortKeyItemData,
var hasTransactions, newDefaultSortKeyItem, newDefaultSortKeyItemData,
surfaceModel = this.surface.getModel(),
currentDefaultSortKeyItem = this.getDefaultSortKeyItem();
@ -186,10 +186,10 @@ ve.ui.MWMetaDialog.prototype.onClose = function ( action ) {
ve.ui.PagedDialog.prototype.onClose.call( this );
// Place transactions made while dialog was open in a common history state
surfaceModel.breakpoint();
hasTransactions = surfaceModel.breakpoint();
// Undo everything done in the dialog and prevent redoing those changes
if ( action === 'cancel' ) {
if ( action === 'cancel' && hasTransactions ) {
surfaceModel.undo();
surfaceModel.truncateUndoStack();
}