diff --git a/src/model/delta/basic-transformations.js b/src/model/delta/basic-transformations.js index 783d700c3..2a254be0c 100644 --- a/src/model/delta/basic-transformations.js +++ b/src/model/delta/basic-transformations.js @@ -103,8 +103,13 @@ function transformMarkerDelta( a, b ) { const transformedDelta = a.clone(); const transformedOp = transformedDelta.operations[ 0 ]; - transformedOp.oldRange = transformedOp.oldRange.getTransformedByDelta( b )[ 0 ]; - transformedOp.newRange = transformedOp.newRange.getTransformedByDelta( b )[ 0 ]; + if ( transformedOp.oldRange ) { + transformedOp.oldRange = transformedOp.oldRange.getTransformedByDelta( b )[ 0 ]; + } + + if ( transformedOp.newRange ) { + transformedOp.newRange = transformedOp.newRange.getTransformedByDelta( b )[ 0 ]; + } return [ transformedDelta ]; } diff --git a/tests/model/delta/transform/markerdelta.js b/tests/model/delta/transform/markerdelta.js index 62b3d44e0..559e28879 100644 --- a/tests/model/delta/transform/markerdelta.js +++ b/tests/model/delta/transform/markerdelta.js @@ -232,4 +232,25 @@ describe( 'transform', () => { } ); } ); } ); + + it( 'null ranges of MarkerDelta should not be changed during transformation', () => { + const markerDelta = getMarkerDelta( 'name', null, null, baseVersion ); + + // Transform `markerDelta` by any other delta that has a special transformation case with `MarkerDelta`. + const wrapElement = new Element( 'w' ); + const wrapRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) ); + const wrapDelta = getWrapDelta( wrapRange, wrapElement, baseVersion ); + + const transformed = transform( markerDelta, wrapDelta ); + + expect( transformed.length ).to.equal( 1 ); + expect( transformed[ 0 ].operations.length ).to.equal( 1 ); + + const transformedOp = transformed[ 0 ].operations[ 0 ]; + + expect( transformedOp ).to.be.instanceof( MarkerOperation ); + expect( transformedOp.oldRange ).to.be.null; + expect( transformedOp.newRange ).to.be.null; + expect( transformedOp.name ).to.equal( 'name' ); + } ); } );