8
0
Pārlūkot izejas kodu

Internal: Updated schema use. See ckeditor/ckeditor5-engine#1234.

Piotrek Koszuliński 7 gadi atpakaļ
vecāks
revīzija
ec6c747226

+ 4 - 9
packages/ckeditor5-block-quote/src/blockquoteengine.js

@@ -37,16 +37,11 @@ export default class BlockQuoteEngine extends Plugin {
 		} );
 
 		// Disallow blockQuote in blockQuote.
-		schema.on( 'checkChild', ( evt, args ) => {
-			const ctx = args[ 0 ];
-			const child = args[ 1 ];
-			const childRule = schema.getDefinition( child );
-
-			if ( childRule && childRule.name == 'blockQuote' && ctx.endsWith( 'blockQuote' ) ) {
-				evt.stop();
-				evt.return = false;
+		schema.addChildCheck( ( ctx, childDef ) => {
+			if ( ctx.endsWith( 'blockQuote' ) && childDef.name == 'blockQuote' ) {
+				return false;
 			}
-		}, { priority: 'high' } );
+		} );
 
 		buildViewConverter().for( editor.data.viewToModel )
 			.fromElement( 'blockquote' )

+ 6 - 13
packages/ckeditor5-block-quote/tests/blockquotecommand.js

@@ -125,12 +125,9 @@ describe( 'BlockQuoteCommand', () => {
 			'is false when selection is in an element which cannot be wrapped with blockQuote' +
 			'(because mQ is not allowed in its parent)',
 			() => {
-				model.schema.on( 'checkChild', ( evt, args ) => {
-					const def = model.schema.getDefinition( args[ 1 ] );
-
-					if ( def.name == 'blockQuote' ) {
-						evt.stop();
-						evt.return = false;
+				model.schema.addChildCheck( ( ctx, childDef ) => {
+					if ( childDef.name == 'blockQuote' ) {
+						return false;
 					}
 				} );
 
@@ -380,13 +377,9 @@ describe( 'BlockQuoteCommand', () => {
 			it( 'should not wrap a block which can not be in a quote', () => {
 				// blockQuote is allowed in root, but fooBlock can not be inside blockQuote.
 				model.schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
-				model.schema.on( 'checkChild', ( evt, args ) => {
-					const def = model.schema.getDefinition( args[ 1 ] );
-					const ctx = args[ 0 ];
-
-					if ( ctx.endsWith( 'blockQuote' ) && def.name == 'fooBlock' ) {
-						evt.stop();
-						evt.return = false;
+				model.schema.addChildCheck( ( ctx, childDef ) => {
+					if ( ctx.endsWith( 'blockQuote' ) && childDef.name == 'fooBlock' ) {
+						return false;
 					}
 				} );