From 0b9934b2ccb1d031fe4b00c5f2090d6c087f0f39 Mon Sep 17 00:00:00 2001 From: Catrope Date: Wed, 20 Jun 2012 23:30:25 -0700 Subject: [PATCH] Fix adjustment of newRange in TransactionProcessor * Adjust both start and end for preceding operations * Adjust end for the current operation as well Change-Id: I2f96d609bddf3788aa5700ad1f0b46208f3517d7 --- modules/ve/dm/ve.dm.TransactionProcessor.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/ve/dm/ve.dm.TransactionProcessor.js b/modules/ve/dm/ve.dm.TransactionProcessor.js index 4fb7118503..839563e26e 100644 --- a/modules/ve/dm/ve.dm.TransactionProcessor.js +++ b/modules/ve/dm/ve.dm.TransactionProcessor.js @@ -243,7 +243,8 @@ ve.dm.TransactionProcessor.processors.replace = function( op ) { minInsertLevel = 0, coveringRange, scopeStart, - scopeEnd; + scopeEnd, + opAdjustment = 0; while ( true ) { if ( operation.type == 'replace' ) { var opRemove = this.reversed ? operation.insert : operation.remove, @@ -323,6 +324,7 @@ ve.dm.TransactionProcessor.processors.replace = function( op ) { } // Update adjustment this.adjustment += opInsert.length - opRemove.length; + opAdjustment += opInsert.length - opRemove.length; } else { // We know that other operations won't cause adjustments, so we // don't have to update adjustment @@ -341,8 +343,12 @@ ve.dm.TransactionProcessor.processors.replace = function( op ) { // From all the affected ranges we have gathered, compute a range that covers all // of them, and rebuild that coveringRange = ve.Range.newCoveringRange( affectedRanges ); - this.synchronizer.pushRebuild( coveringRange, new ve.Range( coveringRange.start, - coveringRange.end + this.adjustment ) + this.synchronizer.pushRebuild( + coveringRange, + new ve.Range( + coveringRange.start + this.adjustment - opAdjustment, + coveringRange.end + this.adjustment + ) ); } };