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

Internal: Allowed $marker element in any parent element. #1698

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ export default class Model {
} );
this.schema.extend( '$text', { allowIn: '$clipboardHolder' } );

// Element needed by `upcastElementToMarker` converter.
// This element temporarily represents marker bound during conversion process and is removed
// at the end of conversion. `UpcastDispatcher` or at least `Conversion` class looks like a better for this
// registration but both know nothing about Schema.
this.schema.register( '$marker', {
allowIn: [ '$root', '$block' ]
// An element needed by the `upcastElementToMarker` converter.
// This element temporarily represents marker bound during the conversion process and is removed
scofalik marked this conversation as resolved.
Show resolved Hide resolved
// at the end of the conversion. `UpcastDispatcher` or at least `Conversion` class looks like a
// better place for this registration but both know nothing about the Schema.
scofalik marked this conversation as resolved.
Show resolved Hide resolved
this.schema.register( '$marker' );
this.schema.addChildCheck( ( context, childDefinition ) => {
if ( childDefinition.name === '$marker' ) {
return true;
}
} );

injectSelectionPostFixer( this );
Expand Down
9 changes: 7 additions & 2 deletions tests/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ describe( 'Model', () => {
} );

it( 'registers $marker to the schema', () => {
model.document.createRoot( '$anywhere', 'anywhere' );
schema.register( 'anything' );

expect( schema.isRegistered( '$marker' ) ).to.be.true;
expect( schema.checkChild( [ '$root' ], '$marker' ), 1 ).to.be.true;
expect( schema.checkChild( [ '$block' ], '$marker' ), 1 ).to.be.true;
expect( schema.checkChild( [ '$root' ], '$marker' ) ).to.be.true;
expect( schema.checkChild( [ '$block' ], '$marker' ) ).to.be.true;
expect( schema.checkChild( [ '$anywhere' ], '$marker' ) ).to.be.true;
expect( schema.checkChild( [ 'anything' ], '$marker' ) ).to.be.true;
} );
} );

Expand Down