From 8b9be7b99c996d60e2dbbd08202d17bdf0a91868 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Fri, 17 Aug 2012 16:24:10 -0700 Subject: [PATCH] Multiple Transactions Make ve.dm.Surface.change accept array of transactions as a parameter (instead of just one) and use it in complex content removal (handled in Surface view). Change-Id: I453b3606cefe140db206f5a2d2c9036bcbd639c9 --- modules/ve/dm/ve.dm.Surface.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js index b11207bf2e..d9fd51b39b 100644 --- a/modules/ve/dm/ve.dm.Surface.js +++ b/modules/ve/dm/ve.dm.Surface.js @@ -85,25 +85,34 @@ ve.dm.Surface.prototype.getFragment = function ( autoSelect ) { * Applies a series of transactions to the content data and sets the selection. * * @method - * @param {ve.dm.Transaction|null} transaction Transaction to apply to the document + * @param {ve.dm.Transaction|ve.dm.Transaction[]|null} transactions One or more transactions to + * process, or null to process none * @param {ve.Range|undefined} selection */ -ve.dm.Surface.prototype.change = function ( transaction, selection ) { - if ( transaction && !transaction.isNoOp() ) { - this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex ); - this.undoIndex = 0; - this.smallStack.push( transaction ); - ve.dm.TransactionProcessor.commit( this.getDocument(), transaction ); +ve.dm.Surface.prototype.change = function ( transactions, selection ) { + if ( transactions ) { + if ( transactions instanceof ve.dm.Transaction ) { + transactions = [transactions]; + } + + for( var i = 0; i < transactions.length; i++ ) { + if ( !transactions[i].isNoOp() ) { + this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex ); + this.undoIndex = 0; + this.smallStack.push( transactions[i] ); + ve.dm.TransactionProcessor.commit( this.getDocument(), transactions[i] ); + } + } } if ( selection && ( !this.selection || !this.selection.equals ( selection ) ) ) { selection.normalize(); this.selection = selection; this.emit('select', this.selection.clone() ); } - if ( transaction ) { - this.emit( 'transact', transaction ); + if ( transactions ) { + this.emit( 'transact', transactions ); } - this.emit( 'change', transaction, selection ); + this.emit( 'change', transactions, selection ); }; /**