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

Commit

Permalink
Merge pull request #1272 from ckeditor/t/ckeditor5-image/171
Browse files Browse the repository at this point in the history
Internal: `Schema#findAllowedParent` should do not allow to split objects. Related: https://github.com/ckeditor/ckeditor5-image/issues/171.
  • Loading branch information
Piotr Jasiun committed Feb 5, 2018
2 parents 3d5cae7 + bb38229 commit b017890
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,8 @@ export default class Schema {
/**
* Tries to find position ancestors that allows to insert given node.
* It starts searching from the given position and goes node by node to the top of the model tree
* as long as {@link module:engine/model/schema~Schema#isLimit limit element} or top-most ancestor won't be reached.
* as long as {@link module:engine/model/schema~Schema#isLimit limit element},
* {@link module:engine/model/schema~Schema#isObject object element} or top-most ancestor won't be reached.
*
* @params {module:engine/model/node~Node} node Node for which allowed parent should be found.
* @params {module:engine/model/position~Position} position Position from searching will start.
Expand All @@ -736,7 +737,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 b017890

Please sign in to comment.