diff --git a/src/model/schema.js b/src/model/schema.js index a68dc3b96..0eed3bb47 100644 --- a/src/model/schema.js +++ b/src/model/schema.js @@ -193,16 +193,11 @@ export default class Schema { this.decorate( 'checkAttribute' ); this.on( 'checkAttribute', ( evt, args ) => { - if ( !( args[ 0 ] instanceof SchemaContext ) ) { - args[ 0 ] = new SchemaContext( args[ 0 ] ); - } + args[ 0 ] = new SchemaContext( args[ 0 ] ); }, { priority: 'highest' } ); this.on( 'checkChild', ( evt, args ) => { - if ( !( args[ 0 ] instanceof SchemaContext ) ) { - args[ 0 ] = new SchemaContext( args[ 0 ] ); - } - + args[ 0 ] = new SchemaContext( args[ 0 ] ); args[ 1 ] = this.getDefinition( args[ 1 ] ); }, { priority: 'highest' } ); } @@ -1072,9 +1067,13 @@ export class SchemaContext { /** * Creates an instance of the context. * - * @param {module:engine/model/schema~SchemaContextDefinition} context + * @param {module:engine/model/schema~SchemaContextDefinition|module:engine/model/schema~SchemaContext} context */ constructor( context ) { + if ( context instanceof SchemaContext ) { + return context; + } + if ( Array.isArray( context ) ) { if ( context[ 0 ] && typeof context[ 0 ] != 'string' && context[ 0 ].is( 'documentFragment' ) ) { context.shift(); diff --git a/tests/model/schema.js b/tests/model/schema.js index ef07b33d6..e17de2a64 100644 --- a/tests/model/schema.js +++ b/tests/model/schema.js @@ -2455,6 +2455,14 @@ describe( 'SchemaContext', () => { expect( Array.from( ctx.getItem( 2 ).getAttributeKeys() ).sort() ).to.deep.equal( [ 'align' ] ); } ); + it( 'creates context based on a SchemaContext instance', () => { + const previousCtx = new SchemaContext( [ 'a', 'b', 'c' ] ); + + const ctx = new SchemaContext( previousCtx ); + + expect( ctx ).to.equal( previousCtx ); + } ); + it( 'filters out DocumentFragment when it is a first item of context - array', () => { const ctx = new SchemaContext( [ new DocumentFragment(), 'paragraph' ] );