Explorar el Código

Docs: Documented possible way of using this method.

Piotrek Koszuliński hace 6 años
padre
commit
d5f716eaf4

+ 1 - 1
packages/ckeditor5-engine/src/model/schema.js

@@ -588,7 +588,7 @@ export default class Schema {
 	 * 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/node~Node|String} node Node for which allowed parent should be found or its name.
 	 * @params {module:engine/model/position~Position} position Position from searching will start.
 	 * @returns {module:engine/model/element~Element|null} element Allowed parent or null if nothing was found.
 	 */

+ 12 - 0
packages/ckeditor5-engine/tests/model/schema.js

@@ -1579,6 +1579,12 @@ describe( 'Schema', () => {
 			expect( allowedParent ).to.equal( r1bQ );
 		} );
 
+		it( 'should return position ancestor that allows to insert given node to it - works with a string too', () => {
+			const allowedParent = schema.findAllowedParent( 'paragraph', Position._createAt( r1bQp, 0 ) );
+
+			expect( allowedParent ).to.equal( r1bQ );
+		} );
+
 		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' );
 
@@ -1622,6 +1628,12 @@ describe( 'Schema', () => {
 
 			expect( parent ).to.null;
 		} );
+
+		it( 'should return null when there is no allowed ancestor for given position – works with a string too', () => {
+			const parent = schema.findAllowedParent( 'section', Position._createAt( r1bQp, 0 ) );
+
+			expect( parent ).to.null;
+		} );
 	} );
 
 	describe( 'removeDisallowedAttributes()', () => {