Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js |
— | — | @@ -25,13 +25,11 @@ |
26 | 26 | * @method |
27 | 27 | * @param {String} type Type of action, can be: "insert", "delete", "rebuild", "resize" or "update" |
28 | 28 | * @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 |
30 | 31 | * @param {Integer} adjustment Node length adjustment, if any |
31 | 32 | */ |
32 | 33 | ve.dm.DocumentSynchronizer.prototype.pushAction = function( type, node, offset, adjustment ) { |
33 | | - if ( offset === undefined ) { |
34 | | - offset = this.model.getOffsetFromNode( node ); |
35 | | - } |
36 | 34 | this.actions.push( { |
37 | 35 | 'type': type, |
38 | 36 | 'node': node, |
— | — | @@ -54,9 +52,13 @@ |
55 | 53 | parent; |
56 | 54 | for ( var i = 0, len = this.actions.length; i < len; i++ ) { |
57 | 55 | action = this.actions[i]; |
58 | | - offset = action.offset + adjustment; |
| 56 | + offset = action.offset === null ? null : ( action.offset + adjustment ); |
59 | 57 | switch ( action.type ) { |
60 | 58 | case 'insert': |
| 59 | + // Compute the offset if it wasn't provided |
| 60 | + if ( offset === null ) { |
| 61 | + offset = this.model.getOffsetFromNode( action.node ); |
| 62 | + } |
61 | 63 | // Insert the new node at the given offset |
62 | 64 | var target = this.model.getNodeFromOffset( offset + 1 ); |
63 | 65 | if ( target === this.model ) { |
— | — | @@ -81,6 +83,10 @@ |
82 | 84 | adjustment -= action.node.getElementLength(); |
83 | 85 | break; |
84 | 86 | case 'rebuild': |
| 87 | + // Compute the offset if it wasn't provided |
| 88 | + if ( offset === null ) { |
| 89 | + offset = this.model.getOffsetFromNode( action.node ); |
| 90 | + } |
85 | 91 | // Replace original node with new node |
86 | 92 | var newNodes = ve.dm.DocumentNode.createNodesFromData( this.model.getData( |
87 | 93 | new ve.Range( offset, action.node.getElementLength() + action.adjustment ) |