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

Improved the docs and the tests.

Kamil Piechaczek 8 лет назад
Родитель
Сommit
00b969592c

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

@@ -383,7 +383,8 @@ export default class Schema {
 	}
 
 	/**
-	 * Returns the lowest limit element defined in {@link module:engine/model/schema~Schema#limits} for passed selection.
+	 * Returns the lowest {@link module:engine/model/schema~Schema#limits limit element} containing the entire
+	 * selection or the root otherwise.
 	 *
 	 * @param {module:engine/model/selection~Selection} selection Selection which returns the common ancestor.
 	 * @returns {module:engine/model/element~Element}

+ 14 - 1
packages/ckeditor5-engine/tests/model/schema/schema.js

@@ -654,9 +654,15 @@ describe( 'Schema', () => {
 			schema.registerItem( 'article', '$block' );
 			schema.registerItem( 'section', '$block' );
 			schema.registerItem( 'paragraph', '$block' );
+			schema.registerItem( 'widget', '$block' );
+			schema.registerItem( 'image', '$block' );
+			schema.registerItem( 'caption', '$block' );
+			schema.allow( { name: 'image', inside: 'widget' } );
+			schema.allow( { name: 'caption', inside: 'image' } );
 			schema.allow( { name: 'paragraph', inside: 'article' } );
 			schema.allow( { name: 'article', inside: 'section' } );
 			schema.allow( { name: 'section', inside: 'div' } );
+			schema.allow( { name: 'widget', inside: 'div' } );
 		} );
 
 		it( 'always returns $root element if any other limit was not defined', () => {
@@ -678,6 +684,7 @@ describe( 'Schema', () => {
 		} );
 
 		it( 'returns the limit element which is the closest element to common ancestor for non-collapsed selection', () => {
+			schema.limits.add( 'article' );
 			schema.limits.add( 'section' );
 
 			setData( doc, '<div><section><article><paragraph>fo[o</paragraph></article>b]ar</section></div>' );
@@ -688,6 +695,8 @@ describe( 'Schema', () => {
 		} );
 
 		it( 'works fine with multi-range selections', () => {
+			schema.limits.add( 'article' );
+			schema.limits.add( 'widget' );
 			schema.limits.add( 'div' );
 
 			setData(
@@ -698,7 +707,11 @@ describe( 'Schema', () => {
 							'<paragraph>[foo]</paragraph>' +
 						'</article>' +
 					'</section>' +
-					'<section>b[]ar</section>' +
+					'<widget>' +
+						'<image>' +
+							'<caption>b[a]r</caption>' +
+						'</image>' +
+					'</widget>' +
 				'</div>'
 			);