瀏覽代碼

Merge branch 'master' into t/1439

Piotrek Koszuliński 7 年之前
父節點
當前提交
ec7e63ec9e

+ 2 - 4
packages/ckeditor5-engine/src/model/utils/deletecontent.js

@@ -118,10 +118,8 @@ function mergeBranches( writer, startPos, endPos ) {
 		return;
 	}
 
-	// If one of the positions is a root, then there's nothing more to merge (at least in the current state of implementation).
-	// Theoretically in this case we could unwrap the <p>: <$root>x[]<p>{}y</p></$root>, but we don't need to support it yet
-	// so let's just abort.
-	if ( !startParent.parent || !endParent.parent ) {
+	// If one of the positions is a limit element, then there's nothing to merge because we don't want to cross the limit boundaries.
+	if ( writer.model.schema.isLimit( startParent ) || writer.model.schema.isLimit( endParent ) ) {
 		return;
 	}
 

+ 58 - 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,60 @@ 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>' );
+			} );
+
+			it( 'should proper merge elements which are inside limit element (nested elements)', () => {
+				setData( model,
+					'<blockQuote>' +
+						'<blockLimit>' +
+							'<blockQuote>' +
+								'<paragraph>Foo.</paragraph>' +
+								'<blockQuote>' +
+									'<paragraph>Foo</paragraph>' +
+								'</blockQuote>' +
+							'</blockQuote>' +
+							'<paragraph>[]Bar</paragraph>' +
+						'</blockLimit>' +
+					'</blockQuote>'
+				);
+
+				model.modifySelection( doc.selection, { direction: 'backward' } );
+				deleteContent( model, doc.selection );
+
+				expect( getData( model ) ).to.equal(
+					'<blockQuote>' +
+						'<blockLimit>' +
+							'<blockQuote>' +
+								'<paragraph>Foo.</paragraph>' +
+								'<blockQuote>' +
+									'<paragraph>Foo[]Bar</paragraph>' +
+								'</blockQuote>' +
+							'</blockQuote>' +
+						'</blockLimit>' +
+					'</blockQuote>'
+				);
+			} );
 		} );
 
 		describe( 'should leave a paragraph if the entire content was selected', () => {