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

Commit

Permalink
Fix: Better handling for MoveOperation x SplitOperation transform…
Browse files Browse the repository at this point in the history
…ation special case.
  • Loading branch information
scofalik committed Oct 9, 2018
1 parent e0e961f commit 1ad61b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ class ContextFactory {
this._setRelation( opA, opB, 'insertAtSource' );
} else if ( opA.targetPosition.isEqual( opB.deletionPosition ) ) {
this._setRelation( opA, opB, 'insertBetween' );
} else if ( opA.targetPosition.isAfter( opB.sourcePosition ) ) {
this._setRelation( opA, opB, 'moveTargetAfter' );
}

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

Expand Down
25 changes: 24 additions & 1 deletion tests/model/operation/transform/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe( 'transform', () => {
expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
} );

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

john.split();
Expand Down Expand Up @@ -321,4 +321,27 @@ describe( 'transform', () => {
john.undo();
expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
} );

// https://github.com/ckeditor/ckeditor5/issues/1288
it( 'remove two groups of blocks then undo, undo', () => {
john.setData(
'<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B[</paragraph><paragraph>C</paragraph><paragraph>D]</paragraph>'
);

john.delete();
john.setSelection( [ 0, 1 ], [ 2, 1 ] );
john.delete();

expectClients( '<paragraph>X</paragraph>' );

john.undo();

expectClients( '<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B</paragraph>' );

john.undo();

expectClients(
'<paragraph>X</paragraph><paragraph>A</paragraph><paragraph>B</paragraph><paragraph>C</paragraph><paragraph>D</paragraph>'
);
} );
} );

0 comments on commit 1ad61b8

Please sign in to comment.