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

Commit

Permalink
Fix: Added a special case for wrap x unwrap transformation to mirror …
Browse files Browse the repository at this point in the history
…a case from unwrap x wrap transformation.
  • Loading branch information
scofalik committed Sep 12, 2018
1 parent 2ef33b1 commit c6ae63e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,14 @@ setTransformation( WrapOperation, WrapOperation, ( a, b, context ) => {
} );

setTransformation( WrapOperation, UnwrapOperation, ( a, b ) => {
// Case 1:
//
// Wrapping element from graveyard got unwrapped. See `UnwrapOperation` x `WrapOperation` mirror case.
//
if ( a.graveyardPosition && b.targetPosition.isEqual( a.graveyardPosition ) ) {
return [ new NoOperation( 0 ) ];
}

const transformed = a.wrappedRange._getTransformedByUnwrapOperation( b );

a.position = transformed.start;
Expand Down Expand Up @@ -2699,7 +2707,7 @@ setTransformation( UnwrapOperation, WrapOperation, ( a, b ) => {
// is going to be transformed by a wrap operation which undoes the previous operation. Operation `a` is
// in a state that is ready for this, but `howMany` has to be set again to a proper value.
//
if ( b.graveyardPosition && compareArrays( a.position.getParentPath(), b.graveyardPosition.path ) == 'same' ) {
if ( b.graveyardPosition && a.targetPosition.isEqual( b.graveyardPosition ) ) {
a.howMany = b.howMany;
}

Expand Down
14 changes: 12 additions & 2 deletions tests/model/operation/transform/unwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ describe( 'transform', () => {
john.undo();

syncClients();
expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
expectClients( '<paragraph>Foo</paragraph>' );

kate.undo();

syncClients();
expectClients( '<paragraph>Foo</paragraph>' );
} );

it( 'the same text', () => {
Expand All @@ -136,12 +141,17 @@ describe( 'transform', () => {
kate.unwrap();

syncClients();
expectClients( '<blockQuote>Foo</blockQuote>' );

john.undo();

syncClients();
expectClients( '<blockQuote>Foo</blockQuote>' );

kate.undo();

expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
syncClients();
expectClients( '<blockQuote>Foo</blockQuote>' );
} );
} );

Expand Down
26 changes: 24 additions & 2 deletions tests/model/operation/transform/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,29 @@ describe( 'transform', () => {
);
} );

it( 'the same element', () => {
it( 'the same element through undo', () => {
john.setData( '[<paragraph>Foo</paragraph>]' );
kate.setData( '<paragraph>[]Foo</paragraph>' );

john.wrap( 'blockQuote' );

syncClients();
expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );

kate.setSelection( [ 0, 0 ] );
kate.unwrap();

syncClients();
expectClients( '<paragraph>Foo</paragraph>' );

john.undo();
kate.undo();

syncClients();
expectClients( '<paragraph>Foo</paragraph>' );
} );

it( 'wrap in unwrapped element', () => {
john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );

Expand All @@ -230,7 +252,7 @@ describe( 'transform', () => {
expectClients( '<div><paragraph>Foo</paragraph></div>' );
} );

it.skip( 'the same element, then undo', () => {
it.skip( 'wrap in unwrapped element, then undo', () => {
// This is interesting scenario actually. Normally in wrap x wrap situation the stronger wrap just wins
// so we won't get incorrect model. But John was actually to make a wrap like this then he had
// <bq><div><p> structure for a while. So it should be possible to revert to it.
Expand Down

0 comments on commit c6ae63e

Please sign in to comment.