瀏覽代碼

First batch of changes updating schema use to match the new API.

Piotrek Koszuliński 8 年之前
父節點
當前提交
4db25b4839
共有 2 個文件被更改,包括 18 次插入15 次删除
  1. 1 1
      packages/ckeditor5-enter/src/entercommand.js
  2. 17 14
      packages/ckeditor5-enter/tests/entercommand.js

+ 1 - 1
packages/ckeditor5-enter/src/entercommand.js

@@ -42,7 +42,7 @@ function enterBlock( model, writer, selection, schema ) {
 	const endElement = range.end.parent;
 
 	// Don't touch the roots and other limit elements.
-	if ( schema.limits.has( startElement.name ) || schema.limits.has( endElement.name ) ) {
+	if ( schema.isLimit( startElement.name ) || schema.isLimit( endElement.name ) ) {
 		// Delete the selected content but only if inside a single limit element.
 		// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>).
 		// This is an edge case and it's hard to tell what should actually happen because such a selection

+ 17 - 14
packages/ckeditor5-enter/tests/entercommand.js

@@ -25,20 +25,23 @@ describe( 'EnterCommand', () => {
 
 				// Note: We could use real names like 'paragraph', but that would make test patterns too long.
 				// Plus, this is actually a good test that the algorithm can be used for any model.
-				schema.registerItem( 'img', '$inline' );
-				schema.registerItem( 'p', '$block' );
-				schema.registerItem( 'h', '$block' );
-				schema.registerItem( 'inlineLimit' );
-				schema.registerItem( 'blockLimit' );
-
-				schema.allow( { name: 'inlineLimit', inside: 'p' } );
-				schema.allow( { name: '$text', inside: 'inlineLimit' } );
-				schema.allow( { name: '$text', inside: '$root' } );
-				schema.allow( { name: 'blockLimit', inside: '$root' } );
-				schema.allow( { name: 'p', inside: 'blockLimit' } );
-
-				schema.limits.add( 'inlineLimit' );
-				schema.limits.add( 'blockLimit' );
+				schema.register( 'img', { allowWhere: '$block' } );
+				schema.register( 'p', {
+					inheritAllFrom: '$block',
+					allowIn: 'blockLimit'
+				} );
+				schema.register( 'h', { inheritAllFrom: '$block' } );
+				schema.register( 'inlineLimit', {
+					allowIn: 'p',
+					isLimit: true
+				} );
+				schema.register( 'blockLimit', {
+					allowIn: '$root',
+					isLimit: true
+				} );
+				schema.extend( '$text', {
+					allowIn: [ 'inlineLimit', '$root' ]
+				} );
 			} );
 	} );