Przeglądaj źródła

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

Piotrek Koszuliński 8 lat temu
rodzic
commit
5b5e1557f0

+ 1 - 1
packages/ckeditor5-heading/src/headingcommand.js

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

+ 3 - 1
packages/ckeditor5-heading/src/headingengine.js

@@ -58,7 +58,9 @@ export default class HeadingEngine extends Plugin {
 			// Skip paragraph - it is defined in required Paragraph feature.
 			if ( option.modelElement !== defaultModelElement ) {
 				// Schema.
-				editor.model.schema.register( option.modelElement, '$block' );
+				editor.model.schema.register( option.modelElement, {
+					inheritAllFrom: '$block'
+				} );
 
 				// Build converter from model to view for data and editing pipelines.
 				buildModelConverter().for( data.modelToView, editing.modelToView )

+ 29 - 5
packages/ckeditor5-heading/tests/headingcommand.js

@@ -31,7 +31,7 @@ describe( 'HeadingCommand', () => {
 
 			for ( const option of options ) {
 				commands[ option.modelElement ] = new HeadingCommand( editor, option.modelElement );
-				schema.register( option.modelElement, '$block' );
+				schema.register( option.modelElement, { inheritAllFrom: '$block' } );
 			}
 
 			schema.register( 'notBlock' );
@@ -112,19 +112,20 @@ describe( 'HeadingCommand', () => {
 		} );
 
 		// https://github.com/ckeditor/ckeditor5-heading/issues/73
-		it( 'should not rename blocks which cannot become headings', () => {
+		it( 'should not rename blocks which cannot become headings (heading is not allowed in their parent)', () => {
 			schema.register( 'restricted' );
 			schema.extend( 'restricted', { allowIn: '$root' } );
-			schema.xdisallow( 'heading1', { allowIn: 'restricted' } );
 
 			schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
-			schema.extend( 'fooBlock', { allowIn: 'restricted' } );
+			schema.extend( 'fooBlock', {
+				allowIn: [ 'restricted', '$root' ]
+			} );
 
 			setData(
 				model,
 				'<paragraph>a[bc</paragraph>' +
 				'<restricted><fooBlock></fooBlock></restricted>' +
-				'<paragraph>de]f</paragraph>'
+				'<fooBlock>de]f</fooBlock>'
 			);
 
 			commands.heading1.execute();
@@ -136,6 +137,29 @@ describe( 'HeadingCommand', () => {
 			);
 		} );
 
+		it( 'should not rename blocks which cannot become headings (block is an object)', () => {
+			schema.register( 'image', {
+				isBlock: true,
+				isObject: true,
+				allowIn: '$root'
+			} );
+
+			setData(
+				model,
+				'<paragraph>a[bc</paragraph>' +
+				'<image></image>' +
+				'<paragraph>de]f</paragraph>'
+			);
+
+			commands.heading1.execute();
+
+			expect( getData( model ) ).to.equal(
+				'<heading1>a[bc</heading1>' +
+				'<image></image>' +
+				'<heading1>de]f</heading1>'
+			);
+		} );
+
 		it( 'should use parent batch', () => {
 			const command = commands.heading1;