@@ -179,25 +179,29 @@ const ot = {
179179 // Take the start and the end of the range and transform them by deletion of moved nodes.
180180 // Note that if rangeB was inside AttributeOperation range, only difference.end will be transformed.
181181 // This nicely covers the joining simplification we did in the previous step.
182- difference . start = difference . start . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ;
183- difference . end = difference . end . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ;
182+ const differenceTransformed = new Range (
183+ difference . start . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ,
184+ difference . end . _getTransformedByDeletion ( b . sourcePosition , b . howMany )
185+ ) ;
184186
185187 // MoveOperation pastes nodes into target position. We acknowledge this by proper transformation.
186188 // Note that since we operate on transformed difference range, we should transform by
187189 // previously transformed target position.
188190 // Note that we do not use Position._getTransformedByMove on range boundaries because we need to
189191 // transform by insertion a range as a whole, since newTargetPosition might be inside that range.
190- ranges = difference . _getTransformedByInsertion ( b . getMovedRangeStart ( ) , b . howMany , true , false ) . reverse ( ) ;
192+ ranges = differenceTransformed . _getTransformedByInsertion ( b . getMovedRangeStart ( ) , b . howMany , true , false ) . reverse ( ) ;
191193 }
192194
193195 if ( common !== null ) {
194196 // Here we do not need to worry that newTargetPosition is inside moved range, because that
195197 // would mean that the MoveOperation targets into itself, and that is incorrect operation.
196198 // Instead, we calculate the new position of that part of original range.
197- common . start = common . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
198- common . end = common . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
199+ const commonTransformed = new Range (
200+ common . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ,
201+ common . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) )
202+ ) ;
199203
200- ranges . push ( common ) ;
204+ ranges . push ( commonTransformed ) ;
201205 }
202206
203207 // Map transformed range(s) to operations and return them.
@@ -376,7 +380,7 @@ const ot = {
376380 // Setting and evaluating some variables that will be used in special cases and default algorithm.
377381 //
378382 // Create ranges from `MoveOperations` properties.
379- const rangeA = Range . createFromPositionAndShift ( a . sourcePosition , a . howMany ) ;
383+ let rangeA = Range . createFromPositionAndShift ( a . sourcePosition , a . howMany ) ;
380384 const rangeB = Range . createFromPositionAndShift ( b . sourcePosition , b . howMany ) ;
381385
382386 // Assign `context.isStrong` to a different variable, because the value may change during execution of
@@ -428,8 +432,10 @@ const ot = {
428432 if ( bTargetsToA && rangeA . containsRange ( rangeB , true ) ) {
429433 // There is a mini-special case here, where `rangeB` is on other level than `rangeA`. That's why
430434 // we need to transform `a` operation anyway.
431- rangeA . start = rangeA . start . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , ! includeB ) ;
432- rangeA . end = rangeA . end . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , includeB ) ;
435+ rangeA = new Range (
436+ rangeA . start . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , ! includeB ) ,
437+ rangeA . end . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , includeB )
438+ ) ;
433439
434440 return makeMoveOperationsFromRanges ( [ rangeA ] , newTargetPosition , a ) ;
435441 }
@@ -444,8 +450,10 @@ const ot = {
444450 if ( aTargetsToB && rangeB . containsRange ( rangeA , true ) ) {
445451 // `a` operation is "moved together" with `b` operation.
446452 // Here, just move `rangeA` "inside" `rangeB`.
447- rangeA . start = rangeA . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
448- rangeA . end = rangeA . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
453+ rangeA = new Range (
454+ rangeA . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ,
455+ rangeA . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) )
456+ ) ;
449457
450458 return makeMoveOperationsFromRanges ( [ rangeA ] , newTargetPosition , a ) ;
451459 }
@@ -466,8 +474,10 @@ const ot = {
466474 // Transform `rangeA` by `b` operation and make operation out of it, and that's all.
467475 // Note that this is a simplified version of default case, but here we treat the common part (whole `rangeA`)
468476 // like a one difference part.
469- rangeA . start = rangeA . start . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , ! includeB ) ;
470- rangeA . end = rangeA . end . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , includeB ) ;
477+ rangeA = new Range (
478+ rangeA . start . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , ! includeB ) ,
479+ rangeA . end . _getTransformedByMove ( b . sourcePosition , b . targetPosition , b . howMany , includeB )
480+ ) ;
471481
472482 return makeMoveOperationsFromRanges ( [ rangeA ] , newTargetPosition , a ) ;
473483 }
@@ -500,10 +510,12 @@ const ot = {
500510 // This is an array with one or two ranges. Two ranges if `rangeB` is inside `rangeA`.
501511 const difference = rangeA . getDifference ( rangeB ) ;
502512
503- for ( const range of difference ) {
513+ for ( const rangeInDiff of difference ) {
504514 // Transform those ranges by `b` operation. For example if `b` moved range from before those ranges, fix those ranges.
505- range . start = range . start . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ;
506- range . end = range . end . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ;
515+ const range = new Range (
516+ rangeInDiff . start . _getTransformedByDeletion ( b . sourcePosition , b . howMany ) ,
517+ rangeInDiff . end . _getTransformedByDeletion ( b . sourcePosition , b . howMany )
518+ ) ;
507519
508520 // If `b` operation targets into `rangeA` on the same level, spread `rangeA` into two ranges.
509521 const shouldSpread = compareArrays ( range . start . getParentPath ( ) , b . getMovedRangeStart ( ) . getParentPath ( ) ) == 'same' ;
@@ -513,12 +525,14 @@ const ot = {
513525 }
514526
515527 // Then, we have to manage the "common part" of both move ranges.
516- const common = rangeA . getIntersection ( rangeB ) ;
528+ const intersectionRange = rangeA . getIntersection ( rangeB ) ;
517529
518- if ( common !== null && isStrong && ! bTargetsToA ) {
530+ if ( intersectionRange !== null && isStrong && ! bTargetsToA ) {
519531 // Calculate the new position of that part of original range.
520- common . start = common . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
521- common . end = common . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ;
532+ const common = new Range (
533+ intersectionRange . start . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) ) ,
534+ intersectionRange . end . _getCombined ( b . sourcePosition , b . getMovedRangeStart ( ) )
535+ ) ;
522536
523537 // Take care of proper range order.
524538 //
@@ -627,9 +641,10 @@ function joinRanges( ranges ) {
627641 } else if ( ranges . length == 1 ) {
628642 return ranges [ 0 ] ;
629643 } else {
630- ranges [ 0 ] . end = ranges [ ranges . length - 1 ] . end ;
631-
632- return ranges [ 0 ] ;
644+ return new Range (
645+ ranges [ 0 ] . start ,
646+ ranges [ ranges . length - 1 ] . end
647+ ) ;
633648 }
634649}
635650
0 commit comments