r113849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113848‎ | r113849 | r113850 >
Date:21:02, 14 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
Remove the offset adjustment feature from DocumentSynchronizer. It gets in the way when I try to use this class in TransactionProcessor.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
@@ -46,13 +46,12 @@
4747 ve.dm.DocumentSynchronizer.prototype.synchronize = function() {
4848 // TODO: Normalize the actions list to clean up nested actions
4949 // Perform all actions
50 - var adjustment = 0,
51 - action,
 50+ var action,
5251 offset,
5352 parent;
5453 for ( var i = 0, len = this.actions.length; i < len; i++ ) {
5554 action = this.actions[i];
56 - offset = action.offset === null ? null : ( action.offset + adjustment );
 55+ offset = action.offset;
5756 switch ( action.type ) {
5857 case 'insert':
5958 // Compute the offset if it wasn't provided
@@ -72,15 +71,11 @@
7372 parent = target.getParent();
7473 parent.splice( parent.indexOf( target ), 0, action.node );
7574 }
76 - // Adjust proceeding offsets positively by the length of the node being inserted
77 - adjustment += action.node.getElementLength();
7875 break;
7976 case 'delete':
8077 // Replace original node with new node
8178 parent = action.node.getParent();
8279 parent.splice( parent.indexOf( action.node ), 1 );
83 - // Adjust proceeding offsets negatively by the length of the node being deleted
84 - adjustment -= action.node.getElementLength();
8580 break;
8681 case 'rebuild':
8782 // Compute the offset if it wasn't provided
@@ -93,18 +88,10 @@
9489 ) );
9590 parent = action.node.getParent();
9691 ve.batchedSplice( parent, parent.indexOf( action.node ), 1, newNodes );
97 - // Adjust proceeding offsets by the difference between the original and new nodes
98 - var newNodesLength = 0;
99 - for ( var j = 0, jlen = newNodes.length; j < jlen; j++ ) {
100 - newNodesLength += newNodes[j].getElementLength();
101 - }
102 - adjustment += newNodesLength - action.node.getElementLength();
10392 break;
10493 case 'resize':
10594 // Adjust node length - causes update events to be emitted
10695 action.node.adjustContentLength( action.adjustment );
107 - // Adjust proceeding offsets by the amount the node is being lengthened or shortened
108 - adjustment += action.adjustment;
10996 break;
11097 case 'update':
11198 // Emit update events

Status & tagging log