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

Commit

Permalink
Allowed SchemaContext as a context of SchemaContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jan 30, 2018
1 parent 1c9c010 commit 1fbee48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } );
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions tests/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );

Expand Down

0 comments on commit 1fbee48

Please sign in to comment.