瀏覽代碼

Fix: Added a special case for wrap x unwrap transformation to mirror a case from unwrap x wrap transformation.

Szymon Cofalik 7 年之前
父節點
當前提交
55666a1472

+ 9 - 1
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -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;
@@ -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;
 	}
 

+ 12 - 2
packages/ckeditor5-engine/tests/model/operation/transform/unwrap.js

@@ -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', () => {
@@ -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>' );
 			} );
 		} );
 

+ 24 - 2
packages/ckeditor5-engine/tests/model/operation/transform/wrap.js

@@ -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>' );
 
@@ -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.