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
This commit is contained in:
Catrope 2012-06-20 23:30:25 -07:00 committed by Trevor Parscal
parent 48bba8fcb8
commit 0b9934b2cc

View file

@ -243,7 +243,8 @@ ve.dm.TransactionProcessor.processors.replace = function( op ) {
minInsertLevel = 0, minInsertLevel = 0,
coveringRange, coveringRange,
scopeStart, scopeStart,
scopeEnd; scopeEnd,
opAdjustment = 0;
while ( true ) { while ( true ) {
if ( operation.type == 'replace' ) { if ( operation.type == 'replace' ) {
var opRemove = this.reversed ? operation.insert : operation.remove, var opRemove = this.reversed ? operation.insert : operation.remove,
@ -323,6 +324,7 @@ ve.dm.TransactionProcessor.processors.replace = function( op ) {
} }
// Update adjustment // Update adjustment
this.adjustment += opInsert.length - opRemove.length; this.adjustment += opInsert.length - opRemove.length;
opAdjustment += opInsert.length - opRemove.length;
} else { } else {
// We know that other operations won't cause adjustments, so we // We know that other operations won't cause adjustments, so we
// don't have to update adjustment // 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 // From all the affected ranges we have gathered, compute a range that covers all
// of them, and rebuild that // of them, and rebuild that
coveringRange = ve.Range.newCoveringRange( affectedRanges ); coveringRange = ve.Range.newCoveringRange( affectedRanges );
this.synchronizer.pushRebuild( coveringRange, new ve.Range( coveringRange.start, this.synchronizer.pushRebuild(
coveringRange.end + this.adjustment ) coveringRange,
new ve.Range(
coveringRange.start + this.adjustment - opAdjustment,
coveringRange.end + this.adjustment
)
); );
} }
}; };