r105511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105510‎ | r105511 | r105512 >
Date:03:14, 8 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Revert r105509 and r105507 - taken approach is not gonna work
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/models/es.SurfaceModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js
@@ -68,7 +68,9 @@
6969 item.type,
7070 item.attributes
7171 );
72 - this.toolbar.surfaceView.model.transact( txs );
 72+ for ( var i = 0; i < txs.length; i++ ) {
 73+ this.toolbar.surfaceView.model.transact( txs[i] );
 74+ }
7375 };
7476
7577 es.FormatDropdownTool.prototype.updateState = function( annotations, nodes ) {
Index: trunk/extensions/VisualEditor/modules/es/tools/es.ListButtonTool.js
@@ -29,7 +29,7 @@
3030 insertAt,
3131 removeLength,
3232 data,
33 - txs = [],
 33+ tx,
3434 i,
3535 j;
3636
@@ -82,12 +82,13 @@
8383 styles = listItems[i].getElementAttribute( 'styles' );
8484 if ( styles[styles.length - 1] !== style ) {
8585 styles.splice( styles.length - 1, 1, style );
86 - txs.push( surface.model.getDocument().prepareElementAttributeChange(
 86+ tx = surface.model.getDocument().prepareElementAttributeChange(
8787 surface.documentView.model.getOffsetFromNode( listItems[i], false ),
8888 'set',
8989 'styles',
9090 styles
91 - ) );
 91+ );
 92+ surface.model.transact( tx );
9293 }
9394 }
9495
@@ -112,12 +113,16 @@
113114 }
114115 data = data.concat( [ { 'type': '/list' } ] );
115116
116 - txs.push( surface.model.getDocument().prepareInsertion( insertAt, data ) );
117 - txs.push( surface.model.getDocument().prepareRemoval(
 117+ tx = surface.model.getDocument().prepareInsertion( insertAt, data );
 118+ surface.model.transact( tx );
 119+
 120+ tx = surface.model.getDocument().prepareRemoval(
118121 new es.Range( insertAt + data.length, insertAt + removeLength + data.length )
119 - ) );
 122+ );
 123+ surface.model.transact( tx );
 124+
120125 }
121 - surface.model.transact( txs );
 126+
122127 surface.model.select( selection, true );
123128 };
124129
Index: trunk/extensions/VisualEditor/modules/es/models/es.SurfaceModel.js
@@ -120,14 +120,6 @@
121121 * (such as when replacing - delete, then insert)
122122 */
123123 es.SurfaceModel.prototype.transact = function( transaction, isPartial ) {
124 -
125 - if(es.isArray(transaction)) {
126 - for( var i = 0; i < transaction.length; i++ ) {
127 - this.transact( transaction[i] );
128 - }
129 - return;
130 - }
131 -
132124 // console.log( 'tx:' + $.map( transaction.getOperations(), function(tx) { return tx.type; } ).join(",")
133125 // + ' isPartial:' + isPartial );
134126 this.doc.commit( transaction );
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -613,15 +613,13 @@
614614 }, 10 );
615615 };
616616
617 -es.SurfaceView.prototype.handleDelete = function( backspace, notExecute ) {
 617+es.SurfaceView.prototype.handleDelete = function( backspace, isPartial ) {
618618 var selection = this.currentSelection.clone(),
619619 sourceOffset,
620620 targetOffset,
621621 sourceSplitableNode,
622622 targetSplitableNode,
623 - tx,
624 - txs = [];
625 -
 623+ tx;
626624 if ( selection.from === selection.to ) {
627625 if ( backspace ) {
628626 sourceOffset = selection.to;
@@ -651,13 +649,15 @@
652650 if ( sourceNode === targetNode ||
653651 ( typeof sourceSplitableNode !== 'undefined' &&
654652 sourceSplitableNode.getParent() === targetSplitableNode.getParent() ) ) {
655 - txs.push( this.model.getDocument().prepareRemoval(
 653+ tx = this.model.getDocument().prepareRemoval(
656654 new es.Range( targetOffset, sourceOffset )
657 - ) );
 655+ );
 656+ this.model.transact( tx, isPartial );
658657 } else {
659 - txs.push( this.model.getDocument().prepareInsertion(
 658+ tx = this.model.getDocument().prepareInsertion(
660659 targetOffset, sourceNode.model.getContentData()
661 - ) );
 660+ );
 661+ this.model.transact( tx, isPartial );
662662
663663 var nodeToDelete = sourceNode;
664664 es.DocumentNode.traverseUpstream( nodeToDelete, function( node ) {
@@ -671,31 +671,23 @@
672672 var range = new es.Range();
673673 range.from = this.documentView.getOffsetFromNode( nodeToDelete, false );
674674 range.to = range.from + nodeToDelete.getElementLength();
675 - txs.push( this.model.getDocument().prepareRemoval( range ) );
 675+ tx = this.model.getDocument().prepareRemoval( range );
 676+ this.model.transact( tx, isPartial );
676677 }
677 - if ( notExecute ) {
678 - return txs;
679 - } else {
680 - this.model.transact( txs );
681 - }
682678 } else {
683679 // selection removal
684680 tx = this.model.getDocument().prepareRemoval( selection );
 681+ this.model.transact( tx, isPartial );
685682 selection.from = selection.to = selection.start;
686683 this.model.select( selection );
687 - if ( notExecute ) {
688 - return [tx];
689 - } else {
690 - this.model.transact( tx );
691 - }
692684 }
693685 };
694686
695687 es.SurfaceView.prototype.handleEnter = function() {
696688 var selection = this.currentSelection.clone(),
697 - txs = [];
 689+ tx;
698690 if ( selection.from !== selection.to ) {
699 - txs.concat( this.handleDelete( false, true ) );
 691+ this.handleDelete( false, true );
700692 }
701693 var node = this.documentView.getNodeFromOffset( selection.to, false ),
702694 nodeOffset = this.documentView.getOffsetFromNode( node, false );
@@ -704,11 +696,11 @@
705697 nodeOffset + node.getContentLength() + 1 === selection.to &&
706698 node === es.DocumentViewNode.getSplitableNode( node )
707699 ) {
708 - txs.push( this.documentView.model.prepareInsertion(
 700+ tx = this.documentView.model.prepareInsertion(
709701 nodeOffset + node.getElementLength(),
710702 [ { 'type': 'paragraph' }, { 'type': '/paragraph' } ]
711 - ) );
712 - this.model.transact( txs );
 703+ );
 704+ this.model.transact( tx );
713705 selection.from = selection.to = nodeOffset + node.getElementLength() + 1;
714706 } else {
715707 var stack = [],
@@ -734,8 +726,8 @@
735727 splitable = es.DocumentView.splitRules[ elementType ].self;
736728 return true;
737729 } );
738 - txs.push( this.documentView.model.prepareInsertion( selection.to, stack ) );
739 - this.model.transact( txs );
 730+ tx = this.documentView.model.prepareInsertion( selection.to, stack );
 731+ this.model.transact( tx );
740732 selection.from = selection.to =
741733 this.model.getDocument().getRelativeContentOffset( selection.to, 1 );
742734 }
@@ -764,15 +756,17 @@
765757 this.$input.val( '' );
766758
767759 // Prepare and process a transaction
768 - var txs = [];
 760+ var tx;
769761 if ( selection.from != selection.to ) {
770 - txs.push( this.model.getDocument().prepareRemoval( selection ) );
771 - selection.from = selection.to = Math.min( selection.from, selection.to );
 762+ tx = this.model.getDocument().prepareRemoval( selection );
 763+ this.model.transact( tx, true );
 764+ selection.from = selection.to =
 765+ Math.min( selection.from, selection.to );
772766 }
773767 var data = val.split('');
774768 es.DocumentModel.addAnnotationsToData( data, this.getInsertionAnnotations() );
775 - txs.push( this.model.getDocument().prepareInsertion( selection.from, data ) );
776 - this.model.transact( txs );
 769+ tx = this.model.getDocument().prepareInsertion( selection.from, data );
 770+ this.model.transact( tx );
777771
778772 // Move the selection
779773 selection.from += val.length;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105507Pass array of transactions to transact method if all those transactions are p...inez01:09, 8 December 2011
r105509Temporary fix for transact method to accept array of transactions.inez01:17, 8 December 2011

Status & tagging log