@@ -348,15 +348,16 @@ addTransformationCase( WrapDelta, SplitDelta, ( a, b, context ) => {
348348
349349// Add special case for RenameDelta x SplitDelta transformation.
350350addTransformationCase ( RenameDelta , SplitDelta , ( a , b , context ) => {
351- const splitPosition = new Position ( b . position . root , b . position . path . slice ( 0 , - 1 ) ) ;
351+ const undoMode = context . aWasUndone || context . bWasUndone ;
352+ const posBeforeSplitParent = new Position ( b . position . root , b . position . path . slice ( 0 , - 1 ) ) ;
352353
353354 const deltas = defaultTransform ( a , b , context ) ;
354355
355- if ( a . operations [ 0 ] . position . isEqual ( splitPosition ) ) {
356+ if ( ! undoMode && a . operations [ 0 ] . position . isEqual ( posBeforeSplitParent ) ) {
356357 // If a node that has been split has it's name changed, we should also change name of
357358 // the node created during splitting.
358359 const additionalRenameDelta = a . clone ( ) ;
359- additionalRenameDelta . operations [ 0 ] . position = a . operations [ 0 ] . position . getShiftedBy ( 1 ) ;
360+ additionalRenameDelta . operations [ 0 ] . position = posBeforeSplitParent . getShiftedBy ( 1 ) ;
360361
361362 deltas . push ( additionalRenameDelta ) ;
362363 }
@@ -365,20 +366,25 @@ addTransformationCase( RenameDelta, SplitDelta, ( a, b, context ) => {
365366} ) ;
366367
367368// Add special case for SplitDelta x RenameDelta transformation.
368- addTransformationCase ( SplitDelta , RenameDelta , ( a , b ) => {
369- a = a . clone ( ) ;
370-
371- const splitPosition = new Position ( a . position . root , a . position . path . slice ( 0 , - 1 ) ) ;
372-
373- if ( a . _cloneOperation instanceof InsertOperation ) {
374- // If element to split had it's name changed, we have to reflect this change in an element
375- // that is in SplitDelta's InsertOperation.
376- if ( b . operations [ 0 ] . position . isEqual ( splitPosition ) ) {
377- a . _cloneOperation . nodes . getNode ( 0 ) . name = b . operations [ 0 ] . newName ;
378- }
369+ addTransformationCase ( SplitDelta , RenameDelta , ( a , b , context ) => {
370+ const undoMode = context . aWasUndone || context . bWasUndone ;
371+ const posBeforeSplitParent = new Position ( a . position . root , a . position . path . slice ( 0 , - 1 ) ) ;
372+
373+ // If element to split had it's name changed, we have to reflect this by creating additional rename operation.
374+ if ( ! undoMode && b . operations [ 0 ] . position . isEqual ( posBeforeSplitParent ) ) {
375+ const additionalRenameDelta = b . clone ( ) ;
376+ additionalRenameDelta . operations [ 0 ] . position = posBeforeSplitParent . getShiftedBy ( 1 ) ;
377+
378+ // `nodes` is a property that is available only if `SplitDelta` `a` has `InsertOperation`.
379+ // `SplitDelta` may have `ReinsertOperation` instead of `InsertOperation`.
380+ // However, such delta is only created when `MergeDelta` is reversed.
381+ // So if this is not undo mode, it means that `SplitDelta` has `InsertOperation`.
382+ additionalRenameDelta . operations [ 0 ] . oldName = a . _cloneOperation . nodes . getNode ( 0 ) . name ;
383+
384+ return [ a . clone ( ) , additionalRenameDelta ] ;
379385 }
380386
381- return [ a ] ;
387+ return [ a . clone ( ) ] ;
382388} ) ;
383389
384390// Add special case for RemoveDelta x SplitDelta transformation.
0 commit comments