https://www.mediawiki.org/wiki/Special:Code/MediaWiki/105507
Revision: 105507 Author: inez Date: 2011-12-08 01:09:52 +0000 (Thu, 08 Dec 2011) Log Message: ----------- Pass array of transactions to transact method if all those transactions are part of one "interaction" Modified Paths: -------------- trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js Modified: trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js 2011-12-08 01:09:11 UTC (rev 105506) +++ trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js 2011-12-08 01:09:52 UTC (rev 105507) @@ -68,9 +68,7 @@ item.type, item.attributes ); - for ( var i = 0; i < txs.length; i++ ) { - this.toolbar.surfaceView.model.transact( txs[i] ); - } + this.toolbar.surfaceView.model.transact( txs ); }; es.FormatDropdownTool.prototype.updateState = function( annotations, nodes ) { Modified: trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js 2011-12-08 01:09:11 UTC (rev 105506) +++ trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js 2011-12-08 01:09:52 UTC (rev 105507) @@ -29,7 +29,7 @@ insertAt, removeLength, data, - tx, + txs = [], i, j; @@ -82,13 +82,12 @@ styles = listItems[i].getElementAttribute( 'styles' ); if ( styles[styles.length - 1] !== style ) { styles.splice( styles.length - 1, 1, style ); - tx = surface.model.getDocument().prepareElementAttributeChange( + txs.push( surface.model.getDocument().prepareElementAttributeChange( surface.documentView.model.getOffsetFromNode( listItems[i], false ), 'set', 'styles', styles - ); - surface.model.transact( tx ); + ) ); } } @@ -113,16 +112,12 @@ } data = data.concat( [ { 'type': '/list' } ] ); - tx = surface.model.getDocument().prepareInsertion( insertAt, data ); - surface.model.transact( tx ); - - tx = surface.model.getDocument().prepareRemoval( + txs.push( surface.model.getDocument().prepareInsertion( insertAt, data ) ); + txs.push( surface.model.getDocument().prepareRemoval( new es.Range( insertAt + data.length, insertAt + removeLength + data.length ) - ); - surface.model.transact( tx ); - + ) ); } - + surface.model.transact( txs ); surface.model.select( selection, true ); }; Modified: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js =================================================================== --- trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js 2011-12-08 01:09:11 UTC (rev 105506) +++ trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js 2011-12-08 01:09:52 UTC (rev 105507) @@ -613,13 +613,15 @@ }, 10 ); }; -es.SurfaceView.prototype.handleDelete = function( backspace, isPartial ) { +es.SurfaceView.prototype.handleDelete = function( backspace, notExecute ) { var selection = this.currentSelection.clone(), sourceOffset, targetOffset, sourceSplitableNode, targetSplitableNode, - tx; + tx, + txs = []; + if ( selection.from === selection.to ) { if ( backspace ) { sourceOffset = selection.to; @@ -649,15 +651,13 @@ if ( sourceNode === targetNode || ( typeof sourceSplitableNode !== 'undefined' && sourceSplitableNode.getParent() === targetSplitableNode.getParent() ) ) { - tx = this.model.getDocument().prepareRemoval( + txs.push( this.model.getDocument().prepareRemoval( new es.Range( targetOffset, sourceOffset ) - ); - this.model.transact( tx, isPartial ); + ) ); } else { - tx = this.model.getDocument().prepareInsertion( + txs.push( this.model.getDocument().prepareInsertion( targetOffset, sourceNode.model.getContentData() - ); - this.model.transact( tx, isPartial ); + ) ); var nodeToDelete = sourceNode; es.DocumentNode.traverseUpstream( nodeToDelete, function( node ) { @@ -671,23 +671,31 @@ var range = new es.Range(); range.from = this.documentView.getOffsetFromNode( nodeToDelete, false ); range.to = range.from + nodeToDelete.getElementLength(); - tx = this.model.getDocument().prepareRemoval( range ); - this.model.transact( tx, isPartial ); + txs.push( this.model.getDocument().prepareRemoval( range ) ); } + if ( notExecute ) { + return txs; + } else { + this.model.transact( txs ); + } } else { // selection removal tx = this.model.getDocument().prepareRemoval( selection ); - this.model.transact( tx, isPartial ); selection.from = selection.to = selection.start; this.model.select( selection ); + if ( notExecute ) { + return [tx]; + } else { + this.model.transact( tx ); + } } }; es.SurfaceView.prototype.handleEnter = function() { var selection = this.currentSelection.clone(), - tx; + txs = []; if ( selection.from !== selection.to ) { - this.handleDelete( false, true ); + txs.concat( this.handleDelete( false, true ) ); } var node = this.documentView.getNodeFromOffset( selection.to, false ), nodeOffset = this.documentView.getOffsetFromNode( node, false ); @@ -696,11 +704,11 @@ nodeOffset + node.getContentLength() + 1 === selection.to && node === es.DocumentViewNode.getSplitableNode( node ) ) { - tx = this.documentView.model.prepareInsertion( + txs.push( this.documentView.model.prepareInsertion( nodeOffset + node.getElementLength(), [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ] - ); - this.model.transact( tx ); + ) ); + this.model.transact( txs ); selection.from = selection.to = nodeOffset + node.getElementLength() + 1; } else { var stack = [], @@ -726,8 +734,8 @@ splitable = es.DocumentView.splitRules[ elementType ].self; return true; } ); - tx = this.documentView.model.prepareInsertion( selection.to, stack ); - this.model.transact( tx ); + txs.push( this.documentView.model.prepareInsertion( selection.to, stack ) ); + this.model.transact( txs ); selection.from = selection.to = this.model.getDocument().getRelativeContentOffset( selection.to, 1 ); } @@ -756,17 +764,15 @@ this.$input.val( '' ); // Prepare and process a transaction - var tx; + var txs = []; if ( selection.from != selection.to ) { - tx = this.model.getDocument().prepareRemoval( selection ); - this.model.transact( tx, true ); - selection.from = selection.to = - Math.min( selection.from, selection.to ); + txs.push( this.model.getDocument().prepareRemoval( selection ) ); + selection.from = selection.to = Math.min( selection.from, selection.to ); } var data = val.split(''); es.DocumentModel.addAnnotationsToData( data, this.getInsertionAnnotations() ); - tx = this.model.getDocument().prepareInsertion( selection.from, data ); - this.model.transact( tx ); + txs.push( this.model.getDocument().prepareInsertion( selection.from, data ) ); + this.model.transact( txs ); // Move the selection selection.from += val.length; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs