r105410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105409‎ | r105410 | r105411 >
Date:02:13, 7 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed issue with inserting data that starts with closing elements
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js
@@ -256,41 +256,43 @@
257257 };
258258
259259 es.TransactionProcessor.prototype.insert = function( op ) {
260 - var node;
261 - // If the cursor is on the left of a structural offset, it's going to the the parent node of
262 - // the element we want to be inserting into
263 - if ( es.DocumentModel.isStructuralOffset( this.model.data, this.cursor ) ) {
264 - node = this.model.getNodeFromOffset( this.cursor + 1 );
265 - } else {
266 - node = this.model.getNodeFromOffset( this.cursor );
267 - }
268 - var offset;
269 - if ( node.getParent() === this.model ) {
270 - offset = this.model.getOffsetFromNode( node );
271 - } else {
272 - node = this.getScope( node, op.data );
273 - offset = this.model.getOffsetFromNode( node );
274 - }
275 - if ( es.DocumentModel.containsElementData( op.data ) ) {
276 - // Perform insert on linear data model
277 - es.insertIntoArray( this.model.data, this.cursor, op.data );
278 - this.applyAnnotations( this.cursor + op.data.length );
279 - // Synchronize model tree
280 - if ( offset === -1 ) {
281 - throw 'Invalid offset error. Node is not in model tree';
282 - }
 260+ var node = this.model.getNodeFromOffset( this.cursor ),
 261+ offset;
 262+ // Perform insert on linear data model
 263+ es.insertIntoArray( this.model.data, this.cursor, op.data );
 264+ this.applyAnnotations( this.cursor + op.data.length );
 265+ if (
 266+ es.DocumentModel.isStructuralOffset( this.model.data, this.cursor ) &&
 267+ ( typeof op.data[0].type === 'string' && op.data[0].type.charAt( 0 ) !== '/' )
 268+ ) {
 269+ offset = node === this.model ? 0 : this.model.getOffsetFromNode( node );
283270 this.rebuildNodes(
284 - this.model.data.slice( offset, offset + node.getElementLength() + op.data.length ),
285 - [node]
 271+ this.model.data.slice( this.cursor, op.data.length ),
 272+ null,
 273+ node,
 274+ node.getIndexFromOffset( this.cursor - offset )
286275 );
287276 } else {
288 - // Perform insert on linear data model
289 - // TODO this is duplicated from above
290 - es.insertIntoArray( this.model.data, this.cursor, op.data );
291 - this.applyAnnotations( this.cursor + op.data.length );
292 - // Update model tree
293 - node.adjustContentLength( op.data.length, true );
294 - node.emit( 'update', this.cursor - offset );
 277+ if ( node.getParent() === this.model ) {
 278+ offset = this.model.getOffsetFromNode( node );
 279+ } else {
 280+ node = this.getScope( node, op.data );
 281+ offset = this.model.getOffsetFromNode( node );
 282+ }
 283+ if ( es.DocumentModel.containsElementData( op.data ) ) {
 284+ // Synchronize model tree
 285+ if ( offset === -1 ) {
 286+ throw 'Invalid offset error. Node is not in model tree';
 287+ }
 288+ this.rebuildNodes(
 289+ this.model.data.slice( offset, offset + node.getElementLength() + op.data.length ),
 290+ [node]
 291+ );
 292+ } else {
 293+ // Update model tree
 294+ node.adjustContentLength( op.data.length, true );
 295+ node.emit( 'update', this.cursor - offset );
 296+ }
295297 }
296298 this.cursor += op.data.length;
297299 };

Status & tagging log