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

Better handling for MoveOperation x SplitOperation transformation special case #1575

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>'
);
} );
} );