Procházet zdrojové kódy

Added `text` entity in Schema. Fixed AttributeCommand#checkSchema to query at proper position.

Szymon Cofalik před 9 roky
rodič
revize
ff948d27d2

+ 7 - 5
packages/ckeditor5-engine/src/command/attributecommand.js

@@ -32,24 +32,26 @@ export default class AttributeCommand extends Command {
 		const schema = this.editor.document.schema;
 
 		if ( selection.isCollapsed ) {
-			return schema.checkAtPosition( { name: 'inline', attribute: this.attributeKey }, selection.getFirstPosition() );
-		} else if ( selection.hasAnyRange ) {
+			return schema.checkAtPosition( { name: 'text', attribute: this.attributeKey }, selection.getFirstPosition() );
+		} else {
 			const ranges = selection.getRanges();
 
 			for ( let range of ranges ) {
 				const walker = new TreeWalker( { boundaries: range, mergeCharacters: true } );
+				let last = walker.position;
 				let step = walker.next();
 
 				while ( !step.done ) {
 					const query = {
-						name: step.value.item.name || 'inline',
+						name: step.value.item.name || 'text',
 						attribute: this.attributeKey
 					};
 
-					if ( schema.checkAtPosition( query, walker.position ) ) {
+					if ( schema.checkAtPosition( query, last ) ) {
 						return true;
 					}
 
+					last = walker.position;
 					step = walker.next();
 				}
 			}
@@ -101,7 +103,7 @@ export default class AttributeCommand extends Command {
 
 			while ( !step.done ) {
 				const query = {
-					name: step.value.item.name || 'inline',
+					name: step.value.item.name || 'text',
 					attribute: this.attributeKey
 				};
 

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

@@ -27,9 +27,7 @@ export default class Command {
 		if ( this.checkSchema ) {
 			this.on( 'refreshState', ( evt ) => {
 				if ( !this.checkSchema() ) {
-					evt.stop();
-
-					return false;
+					return disableCallback( evt );
 				}
 			} );
 		}

+ 1 - 0
packages/ckeditor5-engine/src/treemodel/schema.js

@@ -103,6 +103,7 @@ export default class Schema {
 		this.registerItem( 'inline', null );
 		this.registerItem( 'block', null );
 		this.registerItem( 'root', null );
+		this.registerItem( 'text', 'inline' );
 
 		this.allow( { name: 'block', inside: 'root' } );
 		this.allow( { name: 'inline', inside: 'block' } );