Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js |
— | — | @@ -44,28 +44,28 @@ |
45 | 45 | }, |
46 | 46 | 'replace': { |
47 | 47 | 'commit': function( op ) { |
48 | | - this.replace( op, false ); |
| 48 | + this.replace( op ); |
49 | 49 | }, |
50 | 50 | 'rollback': function( op ) { |
51 | | - this.replace( op, true ); |
| 51 | + this.replace( op ); |
52 | 52 | } |
53 | 53 | }, |
54 | 54 | // Change element attributes |
55 | 55 | 'attribute': { |
56 | 56 | 'commit': function( op ) { |
57 | | - this.attribute( op, false ); |
| 57 | + this.attribute( op ); |
58 | 58 | }, |
59 | 59 | 'rollback': function( op ) { |
60 | | - this.attribute( op, true ); |
| 60 | + this.attribute( op ); |
61 | 61 | } |
62 | 62 | }, |
63 | 63 | // Change content annotations |
64 | 64 | 'annotate': { |
65 | 65 | 'commit': function( op ) { |
66 | | - this.mark( op, false ); |
| 66 | + this.mark( op ); |
67 | 67 | }, |
68 | 68 | 'rollback': function( op ) { |
69 | | - this.mark( op, true ); |
| 69 | + this.mark( op ); |
70 | 70 | } |
71 | 71 | } |
72 | 72 | }; |
— | — | @@ -88,9 +88,9 @@ |
89 | 89 | return this.operations[this.operationIndex++] || false; |
90 | 90 | }; |
91 | 91 | |
92 | | -ve.dm.TransactionProcessor.prototype.executeOperation = function( op, method ) { |
| 92 | +ve.dm.TransactionProcessor.prototype.executeOperation = function( op ) { |
93 | 93 | if ( op.type in ve.dm.TransactionProcessor.operationMap ) { |
94 | | - ve.dm.TransactionProcessor.operationMap[op.type][method].call( this, op ); |
| 94 | + ve.dm.TransactionProcessor.operationMap[op.type][this.method].call( this, op ); |
95 | 95 | } else { |
96 | 96 | throw 'Invalid operation error. Operation type is not supported: ' + operation.type; |
97 | 97 | } |
— | — | @@ -98,10 +98,16 @@ |
99 | 99 | |
100 | 100 | ve.dm.TransactionProcessor.prototype.process = function( method ) { |
101 | 101 | var op; |
| 102 | + // Store the method (commit or rollback) and the operations array so executeOperation() |
| 103 | + // can access them easily |
| 104 | + this.method = method; |
102 | 105 | this.operations = this.transaction.getOperations(); |
| 106 | + |
| 107 | + // This loop is factored this way to allow operations to be skipped over or executed |
| 108 | + // from within other operations |
103 | 109 | this.operationIndex = 0; |
104 | 110 | while ( ( op = this.nextOperation() ) ) { |
105 | | - this.executeOperation( op, method ); |
| 111 | + this.executeOperation( op ); |
106 | 112 | } |
107 | 113 | }; |
108 | 114 | |
— | — | @@ -454,8 +460,9 @@ |
455 | 461 | } |
456 | 462 | }; |
457 | 463 | |
458 | | -ve.dm.TransactionProcessor.prototype.replace = function( op, invert ) { |
459 | | - var remove = invert ? op.replacement : op.remove, |
| 464 | +ve.dm.TransactionProcessor.prototype.replace = function( op ) { |
| 465 | + var invert = this.method == 'rollback', |
| 466 | + remove = invert ? op.replacement : op.remove, |
460 | 467 | replacement = invert ? op.remove : op.replacement; |
461 | 468 | // remove is provided only for OT / conflict resolution and for |
462 | 469 | // reversibility, we don't actually verify it here |
— | — | @@ -468,8 +475,9 @@ |
469 | 476 | |
470 | 477 | }; |
471 | 478 | |
472 | | -ve.dm.TransactionProcessor.prototype.attribute = function( op, invert ) { |
473 | | - var element = this.model.data[this.cursor]; |
| 479 | +ve.dm.TransactionProcessor.prototype.attribute = function( op ) { |
| 480 | + var invert = this.method == 'rollback', |
| 481 | + element = this.model.data[this.cursor]; |
474 | 482 | if ( element.type === undefined ) { |
475 | 483 | throw 'Invalid element error. Can not set attributes on non-element data.'; |
476 | 484 | } |
— | — | @@ -506,8 +514,9 @@ |
507 | 515 | } |
508 | 516 | }; |
509 | 517 | |
510 | | -ve.dm.TransactionProcessor.prototype.mark = function( op, invert ) { |
511 | | - var target; |
| 518 | +ve.dm.TransactionProcessor.prototype.mark = function( op ) { |
| 519 | + var invert = this.method == 'rollback', |
| 520 | + target; |
512 | 521 | if ( ( op.method === 'set' && !invert ) || ( op.method === 'clear' && invert ) ) { |
513 | 522 | target = this.set; |
514 | 523 | } else if ( ( op.method === 'clear' && !invert ) || ( op.method === 'set' && invert ) ) { |