r113848 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113847‎ | r113848 | r113849 >
Date:21:02, 14 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
Move computation of missing offset from pushAction() to synchronize(), and only compute offsets for actions that require them. This also fixes an issue where offsets computed by pushAction() would be adjusted incorrectly by pushAction().
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
@@ -25,13 +25,11 @@
2626 * @method
2727 * @param {String} type Type of action, can be: "insert", "delete", "rebuild", "resize" or "update"
2828 * @param {ve.dm.Node} node Node this action is related to
29 - * @param {Integer} offset Offset of node, improves performance if this has already been calculated
 29+ * @param {Integer|null} offset Offset of node, improves performance if this has already been calculated.
 30+ * Only used for insert and rebuild actions
3031 * @param {Integer} adjustment Node length adjustment, if any
3132 */
3233 ve.dm.DocumentSynchronizer.prototype.pushAction = function( type, node, offset, adjustment ) {
33 - if ( offset === undefined ) {
34 - offset = this.model.getOffsetFromNode( node );
35 - }
3634 this.actions.push( {
3735 'type': type,
3836 'node': node,
@@ -54,9 +52,13 @@
5553 parent;
5654 for ( var i = 0, len = this.actions.length; i < len; i++ ) {
5755 action = this.actions[i];
58 - offset = action.offset + adjustment;
 56+ offset = action.offset === null ? null : ( action.offset + adjustment );
5957 switch ( action.type ) {
6058 case 'insert':
 59+ // Compute the offset if it wasn't provided
 60+ if ( offset === null ) {
 61+ offset = this.model.getOffsetFromNode( action.node );
 62+ }
6163 // Insert the new node at the given offset
6264 var target = this.model.getNodeFromOffset( offset + 1 );
6365 if ( target === this.model ) {
@@ -81,6 +83,10 @@
8284 adjustment -= action.node.getElementLength();
8385 break;
8486 case 'rebuild':
 87+ // Compute the offset if it wasn't provided
 88+ if ( offset === null ) {
 89+ offset = this.model.getOffsetFromNode( action.node );
 90+ }
8591 // Replace original node with new node
8692 var newNodes = ve.dm.DocumentNode.createNodesFromData( this.model.getData(
8793 new ve.Range( offset, action.node.getElementLength() + action.adjustment )

Status & tagging log