瀏覽代碼

Consider item attributes when querying the schema.

Piotrek Koszuliński 9 年之前
父節點
當前提交
d93c1193db

+ 8 - 5
packages/ckeditor5-engine/src/datacontroller/insertcontent.js

@@ -3,18 +3,15 @@
  * For licensing, see LICENSE.md.
  */
 
-import { stringify as stringifyModel } from '../dev-utils/model.js';
+// import { stringify as stringifyModel } from '../dev-utils/model.js';
 
 import Position from '../model/position.js';
 import LivePosition from '../model/liveposition.js';
 import Text from '../model/text.js';
 import Element from '../model/element.js';
-// import RootElement from '../model/rootelement.js';
 import Range from '../model/range.js';
 import log from '../../utils/log.js';
 
-window.stringify = stringifyModel; // jshint ignore:line
-
 /**
  * TODO
  *
@@ -39,6 +36,8 @@ export default function insertContent( dataController, batch, selection, content
 		context: [ '$clipboardHolder' ]
 	} );
 
+	// console.log( stringifyModel( modelFragment ) );
+
 	const insertion = new Insertion( dataController, batch, selection.anchor );
 
 	insertion.handleNodes( modelFragment.getChildren() );
@@ -271,7 +270,11 @@ class Insertion {
 	 * @param {engine.model.SchemaPath} path
 	 */
 	_checkIsAllowed( node, path ) {
-		return this.schema.check( { name: this._getNodeSchemaName( node ), inside: path } );
+		return this.schema.check( {
+			name: this._getNodeSchemaName( node ),
+			attributes: Array.from( node.getAttributeKeys() ),
+			inside: path
+		} );
 	}
 
 	_checkIsObject( node ) {

+ 51 - 3
packages/ckeditor5-engine/tests/datacontroller/insertcontent.js

@@ -136,10 +136,17 @@ describe( 'DataController', () => {
 				schema.registerItem( 'heading2', '$block' );
 				schema.registerItem( 'blockWidget' );
 				schema.registerItem( 'inlineWidget' );
+				schema.registerItem( 'listItem', '$block' );
 
 				schema.allow( { name: 'blockWidget', inside: '$root' } );
 				schema.allow( { name: 'inlineWidget', inside: '$block' } );
 				schema.allow( { name: 'inlineWidget', inside: '$clipboardHolder' } );
+				schema.allow( {
+					name: 'listItem',
+					inside: '$root',
+					attributes: [ 'type', 'indent' ]
+				} );
+				schema.requireAttributes( 'listItem', [ 'type', 'indent' ] );
 
 				schema.objects.add( 'blockWidget' );
 				schema.objects.add( 'inlineWidget' );
@@ -190,9 +197,6 @@ describe( 'DataController', () => {
 			);
 
 			describe( 'block to block handling', () => {
-				// Note: This is temporary implementation which gives a quite poor UX.
-				// See https://github.com/ckeditor/ckeditor5-engine/issues/652
-
 				test(
 					'inserts one paragraph',
 					'<paragraph>xyz</paragraph>',
@@ -255,6 +259,50 @@ describe( 'DataController', () => {
 					'<paragraph>[]bar</paragraph>',
 					'[<blockWidget></blockWidget>]<paragraph>bar</paragraph>'
 				);
+
+				test(
+					'inserts one list item',
+					'<listItem indent="0" type="bulleted">xyz</listItem>',
+					'<paragraph>f[]oo</paragraph>',
+					'<paragraph>fxyz[]oo</paragraph>'
+				);
+
+				test(
+					'inserts list item to empty element',
+					'<listItem indent="0" type="bulleted">xyz</listItem>',
+					'<paragraph>[]</paragraph>',
+					'<listItem indent="0" type="bulleted">xyz[]</listItem>'
+				);
+
+				test(
+					'inserts three list items at the end of paragraph',
+					(
+						'<listItem indent="0" type="bulleted">xxx</listItem>' +
+						'<listItem indent="0" type="bulleted">yyy</listItem>' +
+						'<listItem indent="0" type="bulleted">zzz</listItem>'
+					),
+					'<paragraph>foo[]</paragraph>',
+					(
+						'<paragraph>fooxxx</paragraph>' +
+						'<listItem indent="0" type="bulleted">yyy</listItem>' +
+						'<listItem indent="0" type="bulleted">zzz[]</listItem>'
+					)
+				);
+
+				test(
+					'inserts two list items to an empty paragraph',
+					(
+						'<listItem indent="0" type="bulleted">xxx</listItem>' +
+						'<listItem indent="0" type="bulleted">yyy</listItem>'
+					),
+					'<paragraph>a</paragraph><paragraph>[]</paragraph><paragraph>b</paragraph>',
+					(
+						'<paragraph>a</paragraph>' +
+						'<listItem indent="0" type="bulleted">xxx</listItem>' +
+						'<listItem indent="0" type="bulleted">yyy[]</listItem>' +
+						'<paragraph>b</paragraph>'
+					)
+				);
 			} );
 
 			describe( 'mixed content to block', () => {