Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit b92a800

Browse files
author
Piotr Jasiun
authored
Merge pull request #1575 from ckeditor/t/ckeditor5/1288
Fix: Better handling for `MoveOperation` x `SplitOperation` transformation special case. Closes ckeditor/ckeditor5#1288.
2 parents 998bde5 + 1ad61b8 commit b92a800

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/model/operation/transform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ class ContextFactory {
449449
this._setRelation( opA, opB, 'insertAtSource' );
450450
} else if ( opA.targetPosition.isEqual( opB.deletionPosition ) ) {
451451
this._setRelation( opA, opB, 'insertBetween' );
452+
} else if ( opA.targetPosition.isAfter( opB.sourcePosition ) ) {
453+
this._setRelation( opA, opB, 'moveTargetAfter' );
452454
}
453455

454456
break;
@@ -1568,7 +1570,7 @@ setTransformation( MoveOperation, SplitOperation, ( a, b, context ) => {
15681570
// Do not transform if target position is same as split insertion position and this split comes from undo.
15691571
// This should be done on relations but it is too much work for now as it would require relations working in collaboration.
15701572
// We need to make a decision how we will resolve such conflict and this is less harmful way.
1571-
if ( !a.targetPosition.isEqual( b.insertionPosition ) || !b.graveyardPosition ) {
1573+
if ( !a.targetPosition.isEqual( b.insertionPosition ) || !b.graveyardPosition || context.abRelation == 'moveTargetAfter' ) {
15721574
newTargetPosition = a.targetPosition._getTransformedBySplitOperation( b );
15731575
}
15741576

tests/model/operation/transform/undo.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe( 'transform', () => {
238238
expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
239239
} );
240240

241-
it.skip( 'delete split paragraphs', () => {
241+
it( 'delete split paragraphs', () => {
242242
john.setData( '<paragraph>Foo</paragraph><paragraph>B[]ar</paragraph>' );
243243

244244
john.split();
@@ -321,4 +321,27 @@ describe( 'transform', () => {
321321
john.undo();
322322
expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
323323
} );
324+
325+
// https://github.com/ckeditor/ckeditor5/issues/1288
326+
it( 'remove two groups of blocks then undo, undo', () => {
327+
john.setData(
328+
'<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B[</paragraph><paragraph>C</paragraph><paragraph>D]</paragraph>'
329+
);
330+
331+
john.delete();
332+
john.setSelection( [ 0, 1 ], [ 2, 1 ] );
333+
john.delete();
334+
335+
expectClients( '<paragraph>X</paragraph>' );
336+
337+
john.undo();
338+
339+
expectClients( '<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B</paragraph>' );
340+
341+
john.undo();
342+
343+
expectClients(
344+
'<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B</paragraph><paragraph>C</paragraph><paragraph>D</paragraph>'
345+
);
346+
} );
324347
} );

0 commit comments

Comments
 (0)