mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Only undo on MWMetaDialog close if small stack is non-empty
Added return boolean to ve.dm.Surface#breakpoint to indicate if and transactions were pushed to the big stack. Use this value in MWMetaDialog to see if we need to undo on close. Added tests for ve.dm.Surface#breakpoint. Bug: 49630 Change-Id: Ieb2e9e361afe057af93c4d374acc85df58bfb4c3
This commit is contained in:
parent
2d4101168b
commit
84fbd1db2c
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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' );
|
||||
} );
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue