Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Internal: Updated schema use. See ckeditor/ckeditor5-engine#1234.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jan 24, 2018
1 parent 4a4cea0 commit 67bde8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
13 changes: 4 additions & 9 deletions src/blockquoteengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand Down
19 changes: 6 additions & 13 deletions tests/blockquotecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
} );

Expand Down Expand Up @@ -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;
}
} );

Expand Down

0 comments on commit 67bde8f

Please sign in to comment.