From 67bde8fec62c7fb596d76de166d0e94496194813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 24 Jan 2018 13:17:39 +0100 Subject: [PATCH] Internal: Updated schema use. See ckeditor/ckeditor5-engine#1234. --- src/blockquoteengine.js | 13 ++++--------- tests/blockquotecommand.js | 19 ++++++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/blockquoteengine.js b/src/blockquoteengine.js index 2e91da6..46004ef 100644 --- a/src/blockquoteengine.js +++ b/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' ) diff --git a/tests/blockquotecommand.js b/tests/blockquotecommand.js index 6a35ac2..fff57e0 100644 --- a/tests/blockquotecommand.js +++ b/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; } } );