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

Commit

Permalink
Internal: Schema#findAllowedParent should not allow to split objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Feb 2, 2018
1 parent bc35f32 commit 19b39dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@ export default class Schema {
return parent;
}

if ( this.isLimit( parent ) ) {
// Do not split limit elements and objects.
if ( this.isLimit( parent ) || this.isObject( parent ) ) {
return null;
}

Expand Down
20 changes: 17 additions & 3 deletions tests/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,23 +1386,23 @@ describe( 'Schema', () => {
} );
} );

it( 'should return position ancestor that allows to insert given note to it', () => {
it( 'should return position ancestor that allows to insert given node to it', () => {
const node = new Element( 'paragraph' );

const allowedParent = schema.findAllowedParent( node, Position.createAt( r1bQp ) );

expect( allowedParent ).to.equal( r1bQ );
} );

it( 'should return position ancestor that allows to insert given note to it when position is already i such an element', () => {
it( 'should return position ancestor that allows to insert given node to it when position is already i such an element', () => {
const node = new Text( 'text' );

const parent = schema.findAllowedParent( node, Position.createAt( r1bQp ) );

expect( parent ).to.equal( r1bQp );
} );

it( 'should return null when limit element will be reached before allowed parent', () => {
it( 'should return null when limit element is reached before allowed parent', () => {
schema.extend( 'blockQuote', {
isLimit: true
} );
Expand All @@ -1416,6 +1416,20 @@ describe( 'Schema', () => {
expect( parent ).to.null;
} );

it( 'should return null when object element is reached before allowed parent', () => {
schema.extend( 'blockQuote', {
isObject: true
} );
schema.register( 'div', {
allowIn: '$root'
} );
const node = new Element( 'div' );

const parent = schema.findAllowedParent( node, Position.createAt( r1bQp ) );

expect( parent ).to.null;
} );

it( 'should return null when there is no allowed ancestor for given position', () => {
const node = new Element( 'section' );

Expand Down

0 comments on commit 19b39dc

Please sign in to comment.