8
0
Quellcode durchsuchen

Changed: prefixed special items in treeModel.Schema with $ sign.

Szymon Cofalik vor 9 Jahren
Ursprung
Commit
d46831cb04

+ 1 - 2
packages/ckeditor5-engine/src/bold/boldfeature.js

@@ -33,8 +33,7 @@ export default class BoldFeature extends Feature {
 			true
 		);
 
-		this.editor.document.schema.allow( { name: 'inline', attribute: 'bold', inside: 'block' } );
-		this.editor.document.schema.allow( { name: 'block', attribute: 'bold', inside: 'root' } );
+		this.editor.document.schema.allow( { name: '$inline', attribute: 'bold', inside: '$block' } );
 	}
 
 	static get requires() {

+ 3 - 3
packages/ckeditor5-engine/src/command/attributecommand.js

@@ -32,7 +32,7 @@ export default class AttributeCommand extends Command {
 		const schema = this.editor.document.schema;
 
 		if ( selection.isCollapsed ) {
-			return schema.checkAtPosition( { name: 'text', attribute: this.attributeKey }, selection.getFirstPosition() );
+			return schema.checkAtPosition( { name: '$text', attribute: this.attributeKey }, selection.getFirstPosition() );
 		} else {
 			const ranges = selection.getRanges();
 
@@ -43,7 +43,7 @@ export default class AttributeCommand extends Command {
 
 				while ( !step.done ) {
 					const query = {
-						name: step.value.item.name || 'text',
+						name: step.value.item.name || '$text',
 						attribute: this.attributeKey
 					};
 
@@ -103,7 +103,7 @@ export default class AttributeCommand extends Command {
 
 			while ( !step.done ) {
 				const query = {
-					name: step.value.item.name || 'text',
+					name: step.value.item.name || '$text',
 					attribute: this.attributeKey
 				};
 

+ 9 - 6
packages/ckeditor5-engine/tests/attributecommand.js

@@ -26,16 +26,19 @@ beforeEach( () => {
 
 	command = new AttributeCommand( editor, attrKey );
 
-	modelDoc.schema.registerItem( 'p', 'block' );
-	modelDoc.schema.registerItem( 'div', 'block' );
-	modelDoc.schema.registerItem( 'img', 'inline' );
+	modelDoc.schema.registerItem( 'div', '$block' );
+	modelDoc.schema.registerItem( 'p', '$block' );
+	modelDoc.schema.registerItem( 'img', '$inline' );
+
+	// Allow block in "root" (DIV)
+	modelDoc.schema.allow( { name: '$block', inside: 'div' } );
 
 	// Bold text is allowed only in P.
-	modelDoc.schema.allow( { name: 'inline', attribute: 'bold', inside: 'p' } );
-	modelDoc.schema.allow( { name: 'p', attribute: 'bold', inside: 'root' } );
+	modelDoc.schema.allow( { name: '$text', attribute: 'bold', inside: 'p' } );
+	modelDoc.schema.allow( { name: 'p', attribute: 'bold', inside: 'div' } );
 
 	// Disallow bold on image.
-	modelDoc.schema.disallow( { name: 'img', attribute: 'bold', inside: 'root' } );
+	modelDoc.schema.disallow( { name: 'img', attribute: 'bold', inside: 'div' } );
 } );
 
 describe( 'value', () => {

+ 5 - 6
packages/ckeditor5-engine/tests/treemodel/schema/schema.js

@@ -60,9 +60,9 @@ describe( 'registerItem', () => {
 	} );
 
 	it( 'should make registered item inherit allows from base item', () => {
-		schema.registerItem( 'div', '$block' );
+		schema.registerItem( 'image', '$inline' );
 
-		expect( schema.checkForPath( { name: 'div' }, [ '$root' ] ) ).to.be.true;
+		expect( schema.checkForPath( { name: 'image' }, [ '$block' ] ) ).to.be.true;
 	} );
 
 	it( 'should throw if item with given name has already been registered in schema', () => {
@@ -151,8 +151,7 @@ describe( 'checkAtPosition', () => {
 		schema.registerItem( 'header', '$block' );
 		schema.registerItem( 'p', '$block' );
 
-		schema.allow( { name: 'p', inside: 'div' } );
-		schema.allow( { name: 'header', inside: 'div' } );
+		schema.allow( { name: '$block', inside: 'div' } );
 		schema.allow( { name: '$inline', attribute: 'bold', inside: '$block' } );
 
 		schema.disallow( { name: '$inline', attribute: 'bold', inside: 'header' } );
@@ -188,7 +187,7 @@ describe( 'checkAtPosition', () => {
 		expect( schema.checkAtPosition( { name: 'p', attribute: 'bold' }, new Position( root, [ 0, 0 ] ) ) ).to.be.false;
 
 		// Bold text is not allowed in header
-		expect( schema.checkAtPosition( { name: '$inline', attribute: 'bold' }, new Position( root, [ 1, 0 ] ) ) ).to.be.false;
+		expect( schema.checkAtPosition( { name: '$text', attribute: 'bold' }, new Position( root, [ 1, 0 ] ) ) ).to.be.false;
 	} );
 
 	it( 'should return false if given element is not registered in schema', () => {
@@ -202,6 +201,6 @@ describe( 'checkForPath', () => {
 	} );
 
 	it( 'should handle path given as string', () => {
-		expect( schema.checkForPath( { name: '$inline' }, '$block $root' ) ).to.be.true;
+		expect( schema.checkForPath( { name: '$inline' }, '$block $block $block' ) ).to.be.true;
 	} );
 } );