Don't duplicate categories when unlisting

op !== operation in all iterations of this loop except the first,
and using information from one operation to apply another one
doesn't work very well.

The fact that undefined cast to a number is NaN rather than 0
is very unhelpful :(

Also fixed some commas that should be semicolons.

Bug: 52238
Change-Id: I4138c023c955f2866881084506e24bb8b6db5a4d
This commit is contained in:
Roan Kattouw 2013-07-29 17:09:00 -07:00
parent 4b4299ad69
commit 55aaf56038

View file

@ -305,6 +305,7 @@ ve.dm.TransactionProcessor.processors.replace = function ( op ) {
insert = this.reversed ? op.remove : op.insert,
removeMetadata = this.reversed ? op.insertMetadata : op.removeMetadata,
insertMetadata = this.reversed ? op.removeMetadata : op.insertMetadata,
retainMetadata = op.retainMetadata || 0,
removeLinearData = new ve.dm.ElementLinearData( this.document.getStore(), remove ),
insertLinearData = new ve.dm.ElementLinearData( this.document.getStore(), insert ),
removeIsContent = removeLinearData.isContentData(),
@ -324,14 +325,14 @@ ve.dm.TransactionProcessor.processors.replace = function ( op ) {
scopeStart,
scopeEnd,
opAdjustment = 0,
opRemove, opInsert, opRemoveMetadata, opInsertMetadata;
opRemove, opInsert, opRemoveMetadata, opInsertMetadata, opRetainMetadata;
if ( removeIsContent && insertIsContent ) {
// Content replacement
// Update the linear model
this.document.data.batchSplice( this.cursor, remove.length, insert );
// Keep the meta linear model in sync
if ( removeMetadata !== undefined ) {
this.document.metadata.batchSplice( this.cursor + op.retainMetadata, removeMetadata.length, insertMetadata );
this.document.metadata.batchSplice( this.cursor + retainMetadata, removeMetadata.length, insertMetadata );
} else if ( insert.length > remove.length ) {
this.document.metadata.batchSplice( this.cursor + remove.length, 0, new Array( insert.length - remove.length ) );
} else if ( insert.length < remove.length ) {
@ -381,13 +382,14 @@ ve.dm.TransactionProcessor.processors.replace = function ( op ) {
if ( operation.type === 'replace' ) {
opRemove = this.reversed ? operation.insert : operation.remove;
opInsert = this.reversed ? operation.remove : operation.insert;
opRemoveMetadata = this.reversed ? operation.insertMetadata : operation.removeMetadata,
opInsertMetadata = this.reversed ? operation.removeMetadata : operation.insertMetadata,
opRemoveMetadata = this.reversed ? operation.insertMetadata : operation.removeMetadata;
opInsertMetadata = this.reversed ? operation.removeMetadata : operation.insertMetadata;
opRetainMetadata = operation.retainMetadata || 0;
// Update the linear model
this.document.data.batchSplice( this.cursor, opRemove.length, opInsert );
// Keep the meta linear model in sync
if ( opRemoveMetadata !== undefined ) {
this.document.metadata.batchSplice( this.cursor + op.retainMetadata, opRemoveMetadata.length, opInsertMetadata );
this.document.metadata.batchSplice( this.cursor + opRetainMetadata, opRemoveMetadata.length, opInsertMetadata );
} else if ( opInsert.length > opRemove.length ) {
this.document.metadata.batchSplice( this.cursor + opRemove.length, 0, new Array( opInsert.length - opRemove.length ) );
} else if ( opInsert.length < opRemove.length ) {