瀏覽代碼

Third batch of changes aligning schema use to the new API.

Piotrek Koszuliński 8 年之前
父節點
當前提交
807bb4e6ee

+ 1 - 1
packages/ckeditor5-paragraph/src/paragraphcommand.js

@@ -68,5 +68,5 @@ export default class ParagraphCommand extends Command {
 // @param {module:engine/model/schema~Schema} schema The schema of the document.
 // @returns {Boolean}
 function checkCanBecomeParagraph( block, schema ) {
-	return schema.checkChild( block.parent, 'paragraph' );
+	return schema.checkChild( block.parent, 'paragraph' ) && !schema.isObject( block );
 }

+ 24 - 1
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -101,7 +101,7 @@ describe( 'ParagraphCommand', () => {
 		} );
 
 		// https://github.com/ckeditor/ckeditor5-paragraph/issues/24
-		it( 'should not rename blocks which cannot become paragraphs', () => {
+		it( 'should not rename blocks which cannot become paragraphs (paragraph is not allowed in their parent)', () => {
 			model.schema.register( 'restricted' );
 			model.schema.extend( 'restricted', { allowIn: '$root' } );
 			model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
@@ -125,6 +125,29 @@ describe( 'ParagraphCommand', () => {
 			);
 		} );
 
+		it( 'should not rename blocks which cannot become paragraphs (block is an object)', () => {
+			model.schema.register( 'image', {
+				isBlock: true,
+				isObject: true,
+				allowIn: '$root'
+			} );
+
+			setData(
+				model,
+				'<heading1>a[bc</heading1>' +
+				'<image></image>' +
+				'<heading1>de]f</heading1>'
+			);
+
+			command.execute();
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>a[bc</paragraph>' +
+				'<image></image>' +
+				'<paragraph>de]f</paragraph>'
+			);
+		} );
+
 		it( 'should not rename blocks which already are pargraphs', () => {
 			setData( model, '<paragraph>foo[</paragraph><heading1>bar]</heading1>' );