8
0
Просмотр исходного кода

Merge pull request #1272 from ckeditor/t/ckeditor5-image/171

Internal: `Schema#findAllowedParent` should do not allow to split objects. Related: https://github.com/ckeditor/ckeditor5-image/issues/171.
Piotr Jasiun 8 лет назад
Родитель
Сommit
71ca5a7a6b

+ 4 - 2
packages/ckeditor5-engine/src/model/schema.js

@@ -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.
@@ -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;
 			}
 

+ 17 - 3
packages/ckeditor5-engine/tests/model/schema.js

@@ -1386,7 +1386,7 @@ 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 ) );
@@ -1394,7 +1394,7 @@ describe( 'Schema', () => {
 			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 ) );
@@ -1402,7 +1402,7 @@ describe( 'Schema', () => {
 			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
 			} );
@@ -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' );