|
|
@@ -641,4 +641,100 @@ describe( 'Schema', () => {
|
|
|
expect( result[ 1 ].end.path ).to.members( [ 1 ] );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'getLimitElement()', () => {
|
|
|
+ let doc, root;
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ doc = new Document();
|
|
|
+ schema = doc.schema;
|
|
|
+ root = doc.createRoot();
|
|
|
+
|
|
|
+ schema.registerItem( 'div', '$block' );
|
|
|
+ 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', () => {
|
|
|
+ schema.limits.clear();
|
|
|
+
|
|
|
+ setData( doc, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' );
|
|
|
+ expect( schema.getLimitElement( doc.selection ) ).to.equal( root );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'returns the limit element which is the closest element to common ancestor for collapsed selection', () => {
|
|
|
+ schema.limits.add( 'article' );
|
|
|
+ schema.limits.add( 'section' );
|
|
|
+
|
|
|
+ setData( doc, '<div><section><article><paragraph>foo[]bar</paragraph></article></section></div>' );
|
|
|
+
|
|
|
+ const article = root.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
+
|
|
|
+ expect( schema.getLimitElement( doc.selection ) ).to.equal( article );
|
|
|
+ } );
|
|
|
+
|
|
|
+ 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>[foo</article><article>bar]</article></section></div>' );
|
|
|
+
|
|
|
+ const section = root.getNodeByPath( [ 0, 0 ] );
|
|
|
+
|
|
|
+ expect( schema.getLimitElement( doc.selection ) ).to.equal( section );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works fine with multi-range selections', () => {
|
|
|
+ schema.limits.add( 'article' );
|
|
|
+ schema.limits.add( 'widget' );
|
|
|
+ schema.limits.add( 'div' );
|
|
|
+
|
|
|
+ setData(
|
|
|
+ doc,
|
|
|
+ '<div>' +
|
|
|
+ '<section>' +
|
|
|
+ '<article>' +
|
|
|
+ '<paragraph>[foo]</paragraph>' +
|
|
|
+ '</article>' +
|
|
|
+ '</section>' +
|
|
|
+ '<widget>' +
|
|
|
+ '<image>' +
|
|
|
+ '<caption>b[a]r</caption>' +
|
|
|
+ '</image>' +
|
|
|
+ '</widget>' +
|
|
|
+ '</div>'
|
|
|
+ );
|
|
|
+
|
|
|
+ const div = root.getNodeByPath( [ 0 ] );
|
|
|
+ expect( schema.getLimitElement( doc.selection ) ).to.equal( div );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'works fine with multi-range selections even if limit elements are not defined', () => {
|
|
|
+ schema.limits.clear();
|
|
|
+
|
|
|
+ setData(
|
|
|
+ doc,
|
|
|
+ '<div>' +
|
|
|
+ '<section>' +
|
|
|
+ '<article>' +
|
|
|
+ '<paragraph>[foo]</paragraph>' +
|
|
|
+ '</article>' +
|
|
|
+ '</section>' +
|
|
|
+ '</div>' +
|
|
|
+ '<section>b[]ar</section>'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( schema.getLimitElement( doc.selection ) ).to.equal( root );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|