VisualEditor: Transaction with replaceMetadata then replace at the same offset doesn't rollback cleanly


This is kind of a ridiculous case, but it cost me an hour of debugging time, so documenting it here for posterity. It won't be a practical issue until we start composing transactions together.


var data =,

oldDoc = new ve.copyArray( data ) ),
newDoc = new ve.copyArray( data ) ),
tx = new;

tx.pushRetain( 11 );
tx.pushReplaceMetadata( [], [ { metadata element here } ] );
tx.pushReplace( [] , [ 'a', 'b', 'c' ] ); newDoc, tx ); newDoc, tx );

After running this, you'd expect oldDoc.metadata and newDoc.metadata to be equal, but they're not:





When the transaction is rolled back, the metadata element that was added was never removed. I think this is because the content insertion pushes the metadata back, and then when the rollback tries to remove the metadata again, it can't find it. When the metadata replacement and content replacement are swapped, it works fine, so that's my workaround for now.

Version: unspecified
Severity: enhancement

bzimport added a project: Technical-Debt.Via ConduitNov 22 2014, 1:18 AM
bzimport set Reference to bz46138.
Catrope created this task.Via LegacyMar 14 2013, 10:35 PM
Jdforrester-WMF moved this task to Backlog on the VisualEditor workboard.Via WebNov 24 2014, 6:42 PM

Add Comment