浏览代码

Fourth batch of changes aligning schema use to the new API.

Piotrek Koszuliński 8 年之前
父节点
当前提交
2b2d0d2c7a
共有 2 个文件被更改,包括 19 次插入7 次删除
  1. 11 3
      packages/ckeditor5-list/src/converters.js
  2. 8 4
      packages/ckeditor5-list/tests/listcommand.js

+ 11 - 3
packages/ckeditor5-list/src/converters.js

@@ -365,8 +365,14 @@ export function viewModelConverter( evt, data, consumable, conversionApi ) {
 		const type = data.input.parent && data.input.parent.name == 'ol' ? 'numbered' : 'bulleted';
 		writer.setAttribute( 'type', type, listItem );
 
-		// 3. Handle `<li>` children.
-		data.context.push( listItem );
+		let alteredContext = false;
+
+		// See https://github.com/ckeditor/ckeditor5-list/issues/87
+		if ( data.context[ data.context.length - 1 ].name != 'listItem' ) {
+			// 3. Handle `<li>` children.
+			data.context.push( listItem );
+			alteredContext = true;
+		}
 
 		// `listItem`s created recursively should have bigger indent.
 		data.indent++;
@@ -394,7 +400,9 @@ export function viewModelConverter( evt, data, consumable, conversionApi ) {
 		}
 
 		data.indent--;
-		data.context.pop();
+		if ( alteredContext ) {
+			data.context.pop();
+		}
 
 		data.output = items;
 	}

+ 8 - 4
packages/ckeditor5-list/tests/listcommand.js

@@ -27,15 +27,20 @@ describe( 'ListCommand', () => {
 			inheritAllFrom: '$block',
 			allowAttributes: [ 'type', 'indent' ]
 		} );
-		model.schema.register( 'listItem', { inheritAllFrom: '$block' } );
 		model.schema.register( 'paragraph', {
 			inheritAllFrom: '$block',
 			allowIn: 'widget'
 		} );
 		model.schema.register( 'widget', { inheritAllFrom: '$block' } );
 
-		// TODO callback if really needed cause this rule is odd
-		// model.schema.xdisallow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: 'widget' } );
+		model.schema.on( 'checkChild', ( evt, args ) => {
+			const rule = model.schema.getRule( args[ 1 ] );
+
+			if ( args[ 0 ].matchEnd( 'widget' ) && rule.name == 'listItem' ) {
+				evt.stop();
+				evt.return = false;
+			}
+		} );
 
 		setData(
 			model,
@@ -255,7 +260,6 @@ describe( 'ListCommand', () => {
 				it( 'should not rename blocks which cannot become listItems (list item is not allowed in their parent)', () => {
 					model.schema.register( 'restricted' );
 					model.schema.extend( 'restricted', { allowIn: '$root' } );
-					model.schema.xdisallow( 'paragraph', { allowIn: 'restricted' } );
 
 					model.schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
 					model.schema.extend( 'fooBlock', { allowIn: 'restricted' } );