8
0
Pārlūkot izejas kodu

model#deleteContent() will proper merge elements inside limit element.

Kamil Piechaczek 7 gadi atpakaļ
vecāks
revīzija
ed72401beb

+ 6 - 0
packages/ckeditor5-engine/src/model/utils/deletecontent.js

@@ -139,11 +139,17 @@ function mergeBranches( writer, startPos, endPos ) {
 	startPos = Position.createAfter( startParent );
 	endPos = Position.createBefore( endParent );
 
+	// One more check if both positions ended up in the same parent. See: https://github.com/ckeditor/ckeditor5/issues/1265.
+	if ( endParent == startPos.parent ) {
+		return;
+	}
+
 	if ( !endPos.isEqual( startPos ) ) {
 		// In this case, before we merge, we need to move `endParent` to the `startPos`:
 		// <a><b>x[]</b></a><c><d>{}y</d></c>
 		// becomes:
 		// <a><b>x</b>[]<d>y</d></a><c>{}</c>
+
 		writer.insert( endParent, startPos );
 	}
 

+ 26 - 0
packages/ckeditor5-engine/tests/model/utils/deletecontent.js

@@ -772,6 +772,10 @@ describe( 'DataController utils', () => {
 				schema.extend( '$block', { allowIn: 'blockLimit' } );
 
 				schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+				schema.register( 'blockQuote', {
+					allowWhere: '$block',
+					allowContentOf: '$root'
+				} );
 			} );
 
 			test(
@@ -804,6 +808,28 @@ describe( 'DataController utils', () => {
 				'<blockLimit><paragraph>foo [bar</paragraph></blockLimit><blockLimit><paragraph>baz] qux</paragraph></blockLimit>',
 				'<blockLimit><paragraph>foo []</paragraph></blockLimit><blockLimit><paragraph> qux</paragraph></blockLimit>'
 			);
+
+			// See: https://github.com/ckeditor/ckeditor5/issues/1265.
+			it( 'should proper merge two elements which are inside limit element', () => {
+				setData( model,
+					'<blockLimit>' +
+						'<blockQuote>' +
+							'<paragraph>Foo</paragraph>' +
+						'</blockQuote>' +
+						'<paragraph>[]Bar</paragraph>' +
+					'</blockLimit>'
+				);
+
+				model.modifySelection( doc.selection, { direction: 'backward' } );
+				deleteContent( model, doc.selection );
+
+				expect( getData( model ) ).to.equal(
+					'<blockLimit>' +
+						'<blockQuote>' +
+							'<paragraph>Foo[]Bar</paragraph>' +
+						'</blockQuote>' +
+					'</blockLimit>' );
+			} );
 		} );
 
 		describe( 'should leave a paragraph if the entire content was selected', () => {