Bladeren bron

Renamed 3 methods.

Piotrek Koszuliński 8 jaren geleden
bovenliggende
commit
49384c1932

+ 87 - 87
packages/ckeditor5-engine/src/model/schema.js

@@ -14,13 +14,13 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import Range from './range';
 
 /**
- * The model's schema. It defines allowed and disallowed structures of nodes as well as their attributes.
- * The schema rules are usually defined by features and based on them the editing framework and features
- * make decisions how to process the model.
+ * The model's schema. It defines allowed and disallowed structures of nodes as well as nodes' attributes.
+ * The schema is usually defined by features and based on them the editing framework and features
+ * make decisions how to change and process the model.
  *
  * The instance of schema is available in {@link module:engine/model/model~Model#schema `editor.model.schema`}.
  *
- * # Schema rules
+ * # Schema definitions
  *
  * Schema defines allowed model structures and allowed attributes separately. They are also checked separately
  * by using the {@link ~Schema#checkChild} and {@link ~Schema#checkAttribute} methods.
@@ -37,7 +37,7 @@ import Range from './range';
  *
  * This lets the schema know that `<myElement>` may be a child of the `<$root>` element. `$root` is one of generic
  * node types defined by the editing framework. By default, the editor names the main root element a `<$root>`,
- * so the above rule allows `<myElement>` in the main editor element.
+ * so the above definition allows `<myElement>` in the main editor element.
  *
  * In other words, this would be correct:
  *
@@ -63,8 +63,8 @@ import Range from './range';
  *			allowIn: '$block'
  *		} );
  *
- * Those rules can then be reused by features to define their rules in a more extensible way.
- * For example, the {@link module:paragraph/paragraph~Paragraph} feature will define its rules as:
+ * These definitions can then be reused by features to create their own definitions in a more extensible way.
+ * For example, the {@link module:paragraph/paragraph~Paragraph} feature will define its item as:
  *
  *		schema.register( 'paragraph', {
  *			inheritAllFrom: '$block'
@@ -86,8 +86,8 @@ import Range from './range';
  * * The `<paragraph>` element will allow all attributes allowed on `<$block>`.
  * * The `<paragraph>` element will inherit all `is*` properties of `<$block>` (e.g. `isBlock`).
  *
- * Thanks to the fact that `<paragraph>`'s rules are inherited from `<$block>` other features can use the `<$block>`
- * type to indirectly extend `<paragraph>`'s rules. For example, the {@link module:block-quote/blockquote~BlockQuote}
+ * Thanks to the fact that `<paragraph>`'s definition is inherited from `<$block>` other features can use the `<$block>`
+ * type to indirectly extend `<paragraph>`'s definition. For example, the {@link module:block-quote/blockquote~BlockQuote}
  * feature does this:
  *
  *		schema.register( 'blockQuote', {
@@ -96,11 +96,11 @@ import Range from './range';
  *		} );
  *
  * Thanks to that, despite the fact that block quote and paragraph features know nothing about themselves, paragraphs
- * will be allowed in block quotes and block quotes will be allowed in all places where blocks are, so if anyone will
+ * will be allowed in block quotes and block quotes will be allowed in all places where blocks are. So if anyone will
  * register a `<section>` element (with `allowContentOf: '$root'` rule), that `<section>` elements will allow
- * block quotes.
+ * block quotes too.
  *
- * The side effect of such a rule inheritance is that now `<blockQuote>` is allowed in `<blockQuote>` which needs to be
+ * The side effect of such a definition inheritance is that now `<blockQuote>` is allowed in `<blockQuote>` which needs to be
  * resolved by a callback which will disallow this specific structure.
  *
  * ## Defining advanced rules in `checkChild()`'s callbacks
@@ -118,12 +118,12 @@ import Range from './range';
  *			const context = args[ 0 ];
  *			const child = args[ 1 ];
  *
- *			// Pass the child through getRule() to normalize it (child can be passed in multiple formats).
- *			const childRule = schema.getRule( child );
+ *			// Pass the child through getDefinition() to normalize it (child can be passed in multiple formats).
+ *			const childRule = schema.getDefinition( child );
  *
  *			// If checkChild() is called with a context that ends with blockQuote and blockQuote as a child
  *			// to check, make the method return false and stop the event so no other listener will override your decision.
- *			if ( childRule && childRule.name == 'blockQuote' && context.matchEnd( 'blockQuote' ) ) {
+ *			if ( childRule && childRule.name == 'blockQuote' && context.endsWith( 'blockQuote' ) ) {
  *				evt.stop();
  *				evt.return = false;
  *			}
@@ -186,7 +186,7 @@ export default class Schema {
 	 * Creates schema instance.
 	 */
 	constructor() {
-		this._sourceRules = {};
+		this._sourceDefinitions = {};
 
 		this.decorate( 'checkChild' );
 		this.decorate( 'checkAttribute' );
@@ -204,25 +204,25 @@ export default class Schema {
 	 * Registers schema item. Can only be called once for every item name.
 	 *
 	 * @param {String} itemName
-	 * @param {module:engine/model/schema~SchemaItemDefinition} rules
+	 * @param {module:engine/model/schema~SchemaItemDefinition} definition
 	 */
-	register( itemName, rules ) {
-		if ( this._sourceRules[ itemName ] ) {
+	register( itemName, definition ) {
+		if ( this._sourceDefinitions[ itemName ] ) {
 			// TODO docs
 			throw new CKEditorError( 'schema-cannot-register-item-twice: A single item cannot be registered twice in the schema.', {
 				itemName
 			} );
 		}
 
-		this._sourceRules[ itemName ] = [
-			Object.assign( {}, rules )
+		this._sourceDefinitions[ itemName ] = [
+			Object.assign( {}, definition )
 		];
 
 		this._clearCache();
 	}
 
 	/**
-	 * Extends a {@link #register registered} item's rules.
+	 * Extends a {@link #register registered} item's definition.
 	 *
 	 * Extending properties such as `allowIn` will add more items to the existing properties,
 	 * while redefining properties such as `isBlock` will override the previously defined ones.
@@ -236,24 +236,24 @@ export default class Schema {
 	 *			isBlock: false
 	 *		} );
 	 *
-	 *		schema.getRule( 'foo' );
+	 *		schema.getDefinition( 'foo' );
 	 *		//	{
 	 *		//		allowIn: [ '$root', 'blockQuote' ],
 	 *		// 		isBlock: false
 	 *		//	}
 	 *
 	 * @param {String} itemName
-	 * @param {module:engine/model/schema~SchemaItemDefinition} rules
+	 * @param {module:engine/model/schema~SchemaItemDefinition} definition
 	 */
-	extend( itemName, rules ) {
-		if ( !this._sourceRules[ itemName ] ) {
+	extend( itemName, definition ) {
+		if ( !this._sourceDefinitions[ itemName ] ) {
 			// TODO docs
 			throw new CKEditorError( 'schema-cannot-extend-missing-item: Cannot extend an item which was not registered yet.', {
 				itemName
 			} );
 		}
 
-		this._sourceRules[ itemName ].push( Object.assign( {}, rules ) );
+		this._sourceDefinitions[ itemName ].push( Object.assign( {}, definition ) );
 
 		this._clearCache();
 	}
@@ -263,12 +263,12 @@ export default class Schema {
 	 *
 	 * @returns {Object.<String,module:engine/model/schema~SchemaCompiledItemDefinition>}
 	 */
-	getRules() {
-		if ( !this._compiledRules ) {
+	getDefinitions() {
+		if ( !this._compiledDefinitions ) {
 			this._compile();
 		}
 
-		return this._compiledRules;
+		return this._compiledDefinitions;
 	}
 
 	/**
@@ -277,7 +277,7 @@ export default class Schema {
 	 * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
 	 * @returns {module:engine/model/schema~SchemaCompiledItemDefinition}
 	 */
-	getRule( item ) {
+	getDefinition( item ) {
 		let itemName;
 
 		if ( typeof item == 'string' ) {
@@ -290,41 +290,41 @@ export default class Schema {
 			itemName = item.name;
 		}
 
-		return this.getRules()[ itemName ];
+		return this.getDefinitions()[ itemName ];
 	}
 
 	/**
 	 * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
 	 */
 	isRegistered( item ) {
-		return !!this.getRule( item );
+		return !!this.getDefinition( item );
 	}
 
 	/**
 	 * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
 	 */
 	isBlock( item ) {
-		const rule = this.getRule( item );
+		const def = this.getDefinition( item );
 
-		return !!( rule && rule.isBlock );
+		return !!( def && def.isBlock );
 	}
 
 	/**
 	 * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
 	 */
 	isLimit( item ) {
-		const rule = this.getRule( item );
+		const def = this.getDefinition( item );
 
-		return !!( rule && rule.isLimit );
+		return !!( def && def.isLimit );
 	}
 
 	/**
 	 * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
 	 */
 	isObject( item ) {
-		const rule = this.getRule( item );
+		const def = this.getDefinition( item );
 
-		return !!( rule && rule.isObject );
+		return !!( def && def.isObject );
 	}
 
 	/**
@@ -342,13 +342,13 @@ export default class Schema {
 	 * @param {module:engine/model/node~Node|String} child The child to check.
 	 */
 	checkChild( context, child ) {
-		const rule = this.getRule( child );
+		const def = this.getDefinition( child );
 
-		if ( !rule ) {
+		if ( !def ) {
 			return false;
 		}
 
-		return this._checkContextMatch( rule, context );
+		return this._checkContextMatch( def, context );
 	}
 
 	/**
@@ -367,13 +367,13 @@ export default class Schema {
 	 * @param {String} attributeName
 	 */
 	checkAttribute( context, attributeName ) {
-		const rule = this.getRule( context.last );
+		const def = this.getDefinition( context.last );
 
-		if ( !rule ) {
+		if ( !def ) {
 			return false;
 		}
 
-		return rule.allowAttributes.includes( attributeName );
+		return def.allowAttributes.includes( attributeName );
 	}
 
 	/**
@@ -497,56 +497,56 @@ export default class Schema {
 	 * @private
 	 */
 	_clearCache() {
-		this._compiledRules = null;
+		this._compiledDefinitions = null;
 	}
 
 	/**
 	 * @private
 	 */
 	_compile() {
-		const compiledRules = {};
-		const sourceRules = this._sourceRules;
+		const compiledDefinitions = {};
+		const sourceRules = this._sourceDefinitions;
 		const itemNames = Object.keys( sourceRules );
 
 		for ( const itemName of itemNames ) {
-			compiledRules[ itemName ] = compileBaseItemRule( sourceRules[ itemName ], itemName );
+			compiledDefinitions[ itemName ] = compileBaseItemRule( sourceRules[ itemName ], itemName );
 		}
 
 		for ( const itemName of itemNames ) {
-			compileAllowContentOf( compiledRules, itemName );
+			compileAllowContentOf( compiledDefinitions, itemName );
 		}
 
 		for ( const itemName of itemNames ) {
-			compileAllowWhere( compiledRules, itemName );
+			compileAllowWhere( compiledDefinitions, itemName );
 		}
 
 		for ( const itemName of itemNames ) {
-			compileAllowAttributesOf( compiledRules, itemName );
-			compileInheritPropertiesFrom( compiledRules, itemName );
+			compileAllowAttributesOf( compiledDefinitions, itemName );
+			compileInheritPropertiesFrom( compiledDefinitions, itemName );
 		}
 
 		for ( const itemName of itemNames ) {
-			cleanUpAllowIn( compiledRules, itemName );
-			cleanUpAllowAttributes( compiledRules, itemName );
+			cleanUpAllowIn( compiledDefinitions, itemName );
+			cleanUpAllowAttributes( compiledDefinitions, itemName );
 		}
 
-		this._compiledRules = compiledRules;
+		this._compiledDefinitions = compiledDefinitions;
 	}
 
 	/**
 	 * @private
-	 * @param {module:engine/model/schema~SchemaCompiledItemDefinition} rule
+	 * @param {module:engine/model/schema~SchemaCompiledItemDefinition} def
 	 * @param {module:engine/model/schema~SchemaContext} context
 	 * @param {Number} contextItemIndex
 	 */
-	_checkContextMatch( rule, context, contextItemIndex = context.length - 1 ) {
+	_checkContextMatch( def, context, contextItemIndex = context.length - 1 ) {
 		const contextItem = context.getItem( contextItemIndex );
 
-		if ( rule.allowIn.includes( contextItem.name ) ) {
+		if ( def.allowIn.includes( contextItem.name ) ) {
 			if ( contextItemIndex == 0 ) {
 				return true;
 			} else {
-				const parentRule = this.getRule( contextItem );
+				const parentRule = this.getDefinition( contextItem );
 
 				return this._checkContextMatch( parentRule, context, contextItemIndex - 1 );
 			}
@@ -626,7 +626,7 @@ export class SchemaContext {
 		yield* this._items.map( item => item.name );
 	}
 
-	matchEnd( query ) {
+	endsWith( query ) {
 		return Array.from( this.getNames() ).join( ' ' ).endsWith( query );
 	}
 }
@@ -674,11 +674,11 @@ function compileBaseItemRule( sourceItemRules, itemName ) {
 	return itemRule;
 }
 
-function compileAllowContentOf( compiledRules, itemName ) {
-	for ( const allowContentOfItemName of compiledRules[ itemName ].allowContentOf ) {
+function compileAllowContentOf( compiledDefinitions, itemName ) {
+	for ( const allowContentOfItemName of compiledDefinitions[ itemName ].allowContentOf ) {
 		// The allowContentOf property may point to an unregistered element.
-		if ( compiledRules[ allowContentOfItemName ] ) {
-			const allowedChildren = getAllowedChildren( compiledRules, allowContentOfItemName );
+		if ( compiledDefinitions[ allowContentOfItemName ] ) {
+			const allowedChildren = getAllowedChildren( compiledDefinitions, allowContentOfItemName );
 
 			allowedChildren.forEach( allowedItem => {
 				allowedItem.allowIn.push( itemName );
@@ -686,43 +686,43 @@ function compileAllowContentOf( compiledRules, itemName ) {
 		}
 	}
 
-	delete compiledRules[ itemName ].allowContentOf;
+	delete compiledDefinitions[ itemName ].allowContentOf;
 }
 
-function compileAllowWhere( compiledRules, itemName ) {
-	for ( const allowWhereItemName of compiledRules[ itemName ].allowWhere ) {
-		const inheritFrom = compiledRules[ allowWhereItemName ];
+function compileAllowWhere( compiledDefinitions, itemName ) {
+	for ( const allowWhereItemName of compiledDefinitions[ itemName ].allowWhere ) {
+		const inheritFrom = compiledDefinitions[ allowWhereItemName ];
 
 		// The allowWhere property may point to an unregistered element.
 		if ( inheritFrom ) {
 			const allowedIn = inheritFrom.allowIn;
 
-			compiledRules[ itemName ].allowIn.push( ...allowedIn );
+			compiledDefinitions[ itemName ].allowIn.push( ...allowedIn );
 		}
 	}
 
-	delete compiledRules[ itemName ].allowWhere;
+	delete compiledDefinitions[ itemName ].allowWhere;
 }
 
-function compileAllowAttributesOf( compiledRules, itemName ) {
-	for ( const allowAttributeOfItem of compiledRules[ itemName ].allowAttributesOf ) {
-		const inheritFrom = compiledRules[ allowAttributeOfItem ];
+function compileAllowAttributesOf( compiledDefinitions, itemName ) {
+	for ( const allowAttributeOfItem of compiledDefinitions[ itemName ].allowAttributesOf ) {
+		const inheritFrom = compiledDefinitions[ allowAttributeOfItem ];
 
 		if ( inheritFrom ) {
 			const inheritAttributes = inheritFrom.allowAttributes;
 
-			compiledRules[ itemName ].allowAttributes.push( ...inheritAttributes );
+			compiledDefinitions[ itemName ].allowAttributes.push( ...inheritAttributes );
 		}
 	}
 
-	delete compiledRules[ itemName ].allowAttributesOf;
+	delete compiledDefinitions[ itemName ].allowAttributesOf;
 }
 
-function compileInheritPropertiesFrom( compiledRules, itemName ) {
-	const item = compiledRules[ itemName ];
+function compileInheritPropertiesFrom( compiledDefinitions, itemName ) {
+	const item = compiledDefinitions[ itemName ];
 
 	for ( const inheritPropertiesOfItem of item.inheritTypesFrom ) {
-		const inheritFrom = compiledRules[ inheritPropertiesOfItem ];
+		const inheritFrom = compiledDefinitions[ inheritPropertiesOfItem ];
 
 		if ( inheritFrom ) {
 			const typeNames = Object.keys( inheritFrom ).filter( name => name.startsWith( 'is' ) );
@@ -740,15 +740,15 @@ function compileInheritPropertiesFrom( compiledRules, itemName ) {
 
 // Remove items which weren't registered (because it may break some checks or we'd need to complicate them).
 // Make sure allowIn doesn't contain repeated values.
-function cleanUpAllowIn( compiledRules, itemName ) {
-	const itemRule = compiledRules[ itemName ];
-	const existingItems = itemRule.allowIn.filter( itemToCheck => compiledRules[ itemToCheck ] );
+function cleanUpAllowIn( compiledDefinitions, itemName ) {
+	const itemRule = compiledDefinitions[ itemName ];
+	const existingItems = itemRule.allowIn.filter( itemToCheck => compiledDefinitions[ itemToCheck ] );
 
 	itemRule.allowIn = Array.from( new Set( existingItems ) );
 }
 
-function cleanUpAllowAttributes( compiledRules, itemName ) {
-	const itemRule = compiledRules[ itemName ];
+function cleanUpAllowAttributes( compiledDefinitions, itemName ) {
+	const itemRule = compiledDefinitions[ itemName ];
 
 	itemRule.allowAttributes = Array.from( new Set( itemRule.allowAttributes ) );
 }
@@ -786,10 +786,10 @@ function makeInheritAllWork( sourceItemRules, itemRule ) {
 	}
 }
 
-function getAllowedChildren( compiledRules, itemName ) {
-	const itemRule = compiledRules[ itemName ];
+function getAllowedChildren( compiledDefinitions, itemName ) {
+	const itemRule = compiledDefinitions[ itemName ];
 
-	return getValues( compiledRules ).filter( rule => rule.allowIn.includes( itemRule.name ) );
+	return getValues( compiledDefinitions ).filter( def => def.allowIn.includes( itemRule.name ) );
 }
 
 function getValues( obj ) {

+ 3 - 3
packages/ckeditor5-engine/tests/conversion/buildviewconverter.js

@@ -498,9 +498,9 @@ describe( 'View converter builder', () => {
 		schema.on( 'checkChild', ( evt, args ) => {
 			const ctx = args[ 0 ];
 			const child = args[ 1 ];
-			const childRule = schema.getRule( child );
+			const childRule = schema.getDefinition( child );
 
-			if ( childRule.name == 'div' && ctx.matchEnd( '$root' ) ) {
+			if ( childRule.name == 'div' && ctx.endsWith( '$root' ) ) {
 				evt.stop();
 				evt.return = false;
 			}
@@ -531,7 +531,7 @@ describe( 'View converter builder', () => {
 	// 		const context = args[ 0 ];
 	// 		const attributeName = args[ 1 ];
 
-	// 		if ( ctx.matchEnd( 'paragraph $text' ) && attributeName == 'bold' ) {
+	// 		if ( ctx.endsWith( 'paragraph $text' ) && attributeName == 'bold' ) {
 	// 			evt.stop();
 	// 			evt.return = false;
 	// 		}

+ 2 - 2
packages/ckeditor5-engine/tests/conversion/view-to-model-converters.js

@@ -66,9 +66,9 @@ describe( 'view-to-model-converters', () => {
 			schema.on( 'checkChild', ( evt, args ) => {
 				const ctx = args[ 0 ];
 				const child = args[ 1 ];
-				const childRule = schema.getRule( child );
+				const childRule = schema.getDefinition( child );
 
-				if ( childRule.name == '$text' && ctx.matchEnd( '$root' ) ) {
+				if ( childRule.name == '$text' && ctx.endsWith( '$root' ) ) {
 					evt.stop();
 					evt.return = false;
 				}

+ 7 - 7
packages/ckeditor5-engine/tests/manual/tickets/1088/1.js

@@ -42,36 +42,36 @@ ClassicEditor
 			const ctx = args[ 0 ];
 			const attributeName = args[ 1 ];
 
-			if ( ctx.matchEnd( 'heading1 $text' ) && [ 'linkHref', 'italic' ].includes( attributeName ) ) {
+			if ( ctx.endsWith( 'heading1 $text' ) && [ 'linkHref', 'italic' ].includes( attributeName ) ) {
 				evt.stop();
 				evt.return = false;
 			}
 
-			if ( ctx.matchEnd( 'heading2 $text' ) && attributeName == 'italic' ) {
+			if ( ctx.endsWith( 'heading2 $text' ) && attributeName == 'italic' ) {
 				evt.stop();
 				evt.return = false;
 			}
 
-			if ( ctx.matchEnd( 'heading2 $text' ) && attributeName == 'italic' ) {
+			if ( ctx.endsWith( 'heading2 $text' ) && attributeName == 'italic' ) {
 				evt.stop();
 				evt.return = false;
 			}
 
-			if ( ctx.matchEnd( 'blockQuote listItem $text' ) && attributeName == 'linkHref' ) {
+			if ( ctx.endsWith( 'blockQuote listItem $text' ) && attributeName == 'linkHref' ) {
 				evt.stop();
 				evt.return = false;
 			}
 
-			if ( ctx.matchEnd( 'paragraph $text' ) && attributeName == 'bold' ) {
+			if ( ctx.endsWith( 'paragraph $text' ) && attributeName == 'bold' ) {
 				evt.stop();
 				evt.return = false;
 			}
 		} );
 
 		schema.on( 'checkChild', ( evt, args ) => {
-			const rule = schema.getRule( args[ 1 ] );
+			const def = schema.getDefinition( args[ 1 ] );
 
-			if ( args[ 0 ].matchEnd( '$root' ) && rule.name == 'heading3' ) {
+			if ( args[ 0 ].endsWith( '$root' ) && def.name == 'heading3' ) {
 				evt.stop();
 				evt.return = false;
 			}

+ 99 - 99
packages/ckeditor5-engine/tests/model/schema.js

@@ -45,17 +45,17 @@ describe( 'Schema', () => {
 		it( 'allows registering an item', () => {
 			schema.register( 'foo' );
 
-			expect( schema.getRule( 'foo' ) ).to.be.an( 'object' );
+			expect( schema.getDefinition( 'foo' ) ).to.be.an( 'object' );
 		} );
 
-		it( 'copies rules', () => {
-			const rules = {};
+		it( 'copies definitions', () => {
+			const definitions = {};
 
-			schema.register( 'foo', rules );
+			schema.register( 'foo', definitions );
 
-			rules.isBlock = true;
+			definitions.isBlock = true;
 
-			expect( schema.getRules().foo ).to.not.have.property( 'isBlock' );
+			expect( schema.getDefinitions().foo ).to.not.have.property( 'isBlock' );
 		} );
 
 		it( 'throws when trying to register for a single item twice', () => {
@@ -68,25 +68,25 @@ describe( 'Schema', () => {
 	} );
 
 	describe( 'extend()', () => {
-		it( 'allows extending item\'s rules', () => {
+		it( 'allows extending item\'s definitions', () => {
 			schema.register( 'foo' );
 
 			schema.extend( 'foo', {
 				isBlock: true
 			} );
 
-			expect( schema.getRule( 'foo' ) ).to.have.property( 'isBlock', true );
+			expect( schema.getDefinition( 'foo' ) ).to.have.property( 'isBlock', true );
 		} );
 
-		it( 'copies rules', () => {
+		it( 'copies definitions', () => {
 			schema.register( 'foo', {} );
 
-			const rules = {};
-			schema.extend( 'foo', rules );
+			const definitions = {};
+			schema.extend( 'foo', definitions );
 
-			rules.isBlock = true;
+			definitions.isBlock = true;
 
-			expect( schema.getRules().foo ).to.not.have.property( 'isBlock' );
+			expect( schema.getDefinitions().foo ).to.not.have.property( 'isBlock' );
 		} );
 
 		it( 'throws when trying to extend a not yet registered item', () => {
@@ -96,8 +96,8 @@ describe( 'Schema', () => {
 		} );
 	} );
 
-	describe( 'getRules()', () => {
-		it( 'returns compiled rules', () => {
+	describe( 'getDefinitions()', () => {
+		it( 'returns compiled definitions', () => {
 			schema.register( '$root' );
 
 			schema.register( 'foo', {
@@ -108,9 +108,9 @@ describe( 'Schema', () => {
 				isBlock: true
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.foo ).to.deep.equal( {
+			expect( definitions.foo ).to.deep.equal( {
 				name: 'foo',
 				allowIn: [ '$root' ],
 				allowAttributes: [],
@@ -129,17 +129,17 @@ describe( 'Schema', () => {
 				isFoo: false // Just to check that the last one wins.
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.foo ).to.have.property( 'isBlock', true );
-			expect( rules.foo ).to.have.property( 'isFoo', false );
-			expect( rules.foo ).to.have.property( 'isBar', true );
+			expect( definitions.foo ).to.have.property( 'isBlock', true );
+			expect( definitions.foo ).to.have.property( 'isFoo', false );
+			expect( definitions.foo ).to.have.property( 'isBar', true );
 		} );
 
-		it( 'does not recompile rules if not needed', () => {
+		it( 'does not recompile definitions if not needed', () => {
 			schema.register( 'foo' );
 
-			expect( schema.getRules() ).to.equal( schema.getRules() );
+			expect( schema.getDefinitions() ).to.equal( schema.getDefinitions() );
 		} );
 
 		it( 'ensures no duplicates in allowIn', () => {
@@ -151,9 +151,9 @@ describe( 'Schema', () => {
 				allowIn: '$root'
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.foo ).to.deep.equal( {
+			expect( definitions.foo ).to.deep.equal( {
 				name: 'foo',
 				allowIn: [ '$root' ],
 				allowAttributes: []
@@ -165,9 +165,9 @@ describe( 'Schema', () => {
 				allowIn: '$root'
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.foo ).to.deep.equal( {
+			expect( definitions.foo ).to.deep.equal( {
 				name: 'foo',
 				allowIn: [],
 				allowAttributes: []
@@ -182,9 +182,9 @@ describe( 'Schema', () => {
 				allowAttributes: 'foo'
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.paragraph ).to.deep.equal( {
+			expect( definitions.paragraph ).to.deep.equal( {
 				name: 'paragraph',
 				allowIn: [],
 				allowAttributes: [ 'foo' ]
@@ -200,9 +200,9 @@ describe( 'Schema', () => {
 				allowAttributes: 'foo'
 			} );
 
-			const rules = schema.getRules();
+			const definitions = schema.getDefinitions();
 
-			expect( rules.paragraph ).to.deep.equal( {
+			expect( definitions.paragraph ).to.deep.equal( {
 				name: 'paragraph',
 				allowIn: [],
 				allowAttributes: [ 'foo' ]
@@ -210,32 +210,32 @@ describe( 'Schema', () => {
 		} );
 	} );
 
-	describe( 'getRule()', () => {
-		it( 'returns a rule based on an item name', () => {
+	describe( 'getDefinition()', () => {
+		it( 'returns a definition based on an item name', () => {
 			schema.register( 'foo', {
 				isMe: true
 			} );
 
-			expect( schema.getRule( 'foo' ).isMe ).to.be.true;
+			expect( schema.getDefinition( 'foo' ).isMe ).to.be.true;
 		} );
 
-		it( 'returns a rule based on an element name', () => {
+		it( 'returns a definition based on an element name', () => {
 			schema.register( 'foo', {
 				isMe: true
 			} );
 
-			expect( schema.getRule( new Element( 'foo' ) ).isMe ).to.be.true;
+			expect( schema.getDefinition( new Element( 'foo' ) ).isMe ).to.be.true;
 		} );
 
-		it( 'returns a rule based on a text node', () => {
+		it( 'returns a definition based on a text node', () => {
 			schema.register( '$text', {
 				isMe: true
 			} );
 
-			expect( schema.getRule( new Text( 'foo' ) ).isMe ).to.be.true;
+			expect( schema.getDefinition( new Text( 'foo' ) ).isMe ).to.be.true;
 		} );
 
-		it( 'returns a rule based on a text proxy', () => {
+		it( 'returns a definition based on a text proxy', () => {
 			schema.register( '$text', {
 				isMe: true
 			} );
@@ -243,20 +243,20 @@ describe( 'Schema', () => {
 			const text = new Text( 'foo' );
 			const textProxy = new TextProxy( text, 0, 1 );
 
-			expect( schema.getRule( textProxy ).isMe ).to.be.true;
+			expect( schema.getDefinition( textProxy ).isMe ).to.be.true;
 		} );
 
-		it( 'returns a rule based on a schema context item', () => {
+		it( 'returns a definition based on a schema context item', () => {
 			schema.register( 'foo', {
 				isMe: true
 			} );
 			const ctx = new SchemaContext( [ '$root', 'foo' ] );
 
-			expect( schema.getRule( ctx.last ).isMe ).to.be.true;
+			expect( schema.getDefinition( ctx.last ).isMe ).to.be.true;
 		} );
 
 		it( 'returns undefined when trying to get an unregistered item', () => {
-			expect( schema.getRule( '404' ) ).to.be.undefined;
+			expect( schema.getDefinition( '404' ) ).to.be.undefined;
 		} );
 	} );
 
@@ -271,8 +271,8 @@ describe( 'Schema', () => {
 			expect( schema.isRegistered( 'foo' ) ).to.be.false;
 		} );
 
-		it( 'uses getRule()\'s item to rule normalization', () => {
-			const stub = sinon.stub( schema, 'getRule' ).returns( {} );
+		it( 'uses getDefinition()\'s item to definition normalization', () => {
+			const stub = sinon.stub( schema, 'getDefinition' ).returns( {} );
 
 			expect( schema.isRegistered( 'foo' ) ).to.be.true;
 			expect( stub.calledOnce ).to.be.true;
@@ -298,8 +298,8 @@ describe( 'Schema', () => {
 			expect( schema.isBlock( 'foo' ) ).to.be.false;
 		} );
 
-		it( 'uses getRule()\'s item to rule normalization', () => {
-			const stub = sinon.stub( schema, 'getRule' ).returns( { isBlock: true } );
+		it( 'uses getDefinition()\'s item to definition normalization', () => {
+			const stub = sinon.stub( schema, 'getDefinition' ).returns( { isBlock: true } );
 
 			expect( schema.isBlock( 'foo' ) ).to.be.true;
 			expect( stub.calledOnce ).to.be.true;
@@ -325,8 +325,8 @@ describe( 'Schema', () => {
 			expect( schema.isLimit( 'foo' ) ).to.be.false;
 		} );
 
-		it( 'uses getRule()\'s item to rule normalization', () => {
-			const stub = sinon.stub( schema, 'getRule' ).returns( { isLimit: true } );
+		it( 'uses getDefinition()\'s item to definition normalization', () => {
+			const stub = sinon.stub( schema, 'getDefinition' ).returns( { isLimit: true } );
 
 			expect( schema.isLimit( 'foo' ) ).to.be.true;
 			expect( stub.calledOnce ).to.be.true;
@@ -352,8 +352,8 @@ describe( 'Schema', () => {
 			expect( schema.isObject( 'foo' ) ).to.be.false;
 		} );
 
-		it( 'uses getRule()\'s item to rule normalization', () => {
-			const stub = sinon.stub( schema, 'getRule' ).returns( { isObject: true } );
+		it( 'uses getDefinition()\'s item to definition normalization', () => {
+			const stub = sinon.stub( schema, 'getDefinition' ).returns( { isObject: true } );
 
 			expect( schema.isObject( 'foo' ) ).to.be.true;
 			expect( stub.calledOnce ).to.be.true;
@@ -615,13 +615,13 @@ describe( 'Schema', () => {
 				const attributeName = args[ 1 ];
 
 				// Allow 'bold' on p>$text.
-				if ( ctx.matchEnd( 'p $text' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( 'p $text' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = true;
 				}
 
 				// Allow 'bold' on $root>p.
-				if ( ctx.matchEnd( '$root p' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( '$root p' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = true;
 				}
@@ -705,13 +705,13 @@ describe( 'Schema', () => {
 				const attributeName = args[ 1 ];
 
 				// Allow 'bold' on p>$text.
-				if ( ctx.matchEnd( 'p $text' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( 'p $text' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = true;
 				}
 
 				// Allow 'bold' on $root>p.
-				if ( ctx.matchEnd( '$root p' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( '$root p' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = true;
 				}
@@ -756,7 +756,7 @@ describe( 'Schema', () => {
 				const attributeName = args[ 1 ];
 
 				// Allow 'bold' on img>$text.
-				if ( ctx.matchEnd( 'img $text' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( 'img $text' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = true;
 				}
@@ -799,7 +799,7 @@ describe( 'Schema', () => {
 				const attributeName = args[ 1 ];
 
 				// Disallow 'bold' on p>img.
-				if ( ctx.matchEnd( 'p img' ) && attributeName == 'bold' ) {
+				if ( ctx.endsWith( 'p img' ) && attributeName == 'bold' ) {
 					evt.stop();
 					evt.return = false;
 				}
@@ -868,25 +868,25 @@ describe( 'Schema', () => {
 				const attributeName = args[ 1 ];
 
 				// Allow 'a' on div>$text.
-				if ( ctx.matchEnd( 'div $text' ) && attributeName == 'a' ) {
+				if ( ctx.endsWith( 'div $text' ) && attributeName == 'a' ) {
 					evt.stop();
 					evt.return = true;
 				}
 
 				// Allow 'b' on div>paragraph>$text.
-				if ( ctx.matchEnd( 'div paragraph $text' ) && attributeName == 'b' ) {
+				if ( ctx.endsWith( 'div paragraph $text' ) && attributeName == 'b' ) {
 					evt.stop();
 					evt.return = true;
 				}
 
 				// Allow 'a' on div>image.
-				if ( ctx.matchEnd( 'div image' ) && attributeName == 'a' ) {
+				if ( ctx.endsWith( 'div image' ) && attributeName == 'a' ) {
 					evt.stop();
 					evt.return = true;
 				}
 
 				// Allow 'b' on div>paragraph>image.
-				if ( ctx.matchEnd( 'div paragraph image' ) && attributeName == 'b' ) {
+				if ( ctx.endsWith( 'div paragraph image' ) && attributeName == 'b' ) {
 					evt.stop();
 					evt.return = true;
 				}
@@ -925,7 +925,7 @@ describe( 'Schema', () => {
 		} );
 	} );
 
-	describe( 'rules compilation', () => {
+	describe( 'definitions compilation', () => {
 		describe( 'allowIn cases', () => {
 			it( 'passes $root>paragraph', () => {
 				schema.register( '$root' );
@@ -1086,7 +1086,7 @@ describe( 'Schema', () => {
 			} );
 
 			// This checks if some inapropriate caching or preprocessing isn't applied by register().
-			it( 'passes $root>paragraph – paragraph inherits from $block, order of rules does not matter', () => {
+			it( 'passes $root>paragraph – paragraph inherits from $block, order of definitions does not matter', () => {
 				schema.register( '$root' );
 				schema.register( 'paragraph', {
 					allowWhere: '$block'
@@ -1170,7 +1170,7 @@ describe( 'Schema', () => {
 				expect( schema.checkChild( root3, heading1 ), 'heading1' ).to.be.true;
 			} );
 
-			it( 'passes $root2>paragraph – $root2 inherits from $root, order of rules does not matter', () => {
+			it( 'passes $root2>paragraph – $root2 inherits from $root, order of definitions does not matter', () => {
 				schema.register( '$root' );
 				schema.register( '$root2', {
 					allowContentOf: '$root'
@@ -1265,14 +1265,14 @@ describe( 'Schema', () => {
 				expect( schema.checkChild( d, 'a' ) ).to.be.true;
 			} );
 
-			// This case won't pass becuase we compile the rules in a pretty naive way.
-			// To make chains like this work we'd need to repeat compilation of allowContentOf rules
+			// This case won't pass becuase we compile the definitions in a pretty naive way.
+			// To make chains like this work we'd need to repeat compilation of allowContentOf definitions
 			// as long as the previous iteration found something to compile.
 			// This way, even though we'd not compile d<-c in the first run, we'd still find b<-c
 			// and since we've found something, we'd now try d<-c which would work.
 			//
 			// We ignore those situations for now as they are very unlikely to happen and would
-			// significantly raised the complexity of rule compilation.
+			// significantly raised the complexity of definition compilation.
 			//
 			// it( 'passes d>a where d inherits content of c which inherits content of b', () => {
 			// 	schema.register( 'b' );
@@ -1296,8 +1296,8 @@ describe( 'Schema', () => {
 					inheritTypesFrom: '$block'
 				} );
 
-				expect( schema.getRule( 'paragraph' ).isBlock ).to.be.true;
-				expect( schema.getRule( 'paragraph' ).isLimit ).to.be.true;
+				expect( schema.getDefinition( 'paragraph' ).isBlock ).to.be.true;
+				expect( schema.getDefinition( 'paragraph' ).isLimit ).to.be.true;
 			} );
 
 			it( 'inherit properties of other items – support for arrays', () => {
@@ -1311,8 +1311,8 @@ describe( 'Schema', () => {
 					inheritTypesFrom: [ '$block', '$block2' ]
 				} );
 
-				expect( schema.getRule( 'paragraph' ).isBlock ).to.be.true;
-				expect( schema.getRule( 'paragraph' ).isLimit ).to.be.true;
+				expect( schema.getDefinition( 'paragraph' ).isBlock ).to.be.true;
+				expect( schema.getDefinition( 'paragraph' ).isLimit ).to.be.true;
 			} );
 
 			it( 'does not override existing props', () => {
@@ -1325,8 +1325,8 @@ describe( 'Schema', () => {
 					isLimit: false
 				} );
 
-				expect( schema.getRule( 'paragraph' ).isBlock ).to.be.true;
-				expect( schema.getRule( 'paragraph' ).isLimit ).to.be.false;
+				expect( schema.getDefinition( 'paragraph' ).isBlock ).to.be.true;
+				expect( schema.getDefinition( 'paragraph' ).isLimit ).to.be.false;
 			} );
 		} );
 
@@ -1402,9 +1402,9 @@ describe( 'Schema', () => {
 			} );
 		} );
 
-		// We need to handle cases where some independent features registered rules which might use
+		// We need to handle cases where some independent features registered definitions which might use
 		// optional elements (elements which might not have been registered).
-		describe( 'missing structure rules', () => {
+		describe( 'missing structure definitions', () => {
 			it( 'does not break when trying to check a child which is not registered', () => {
 				schema.register( '$root' );
 
@@ -1571,7 +1571,7 @@ describe( 'Schema', () => {
 			} );
 		} );
 
-		describe( 'missing attribute rules', () => {
+		describe( 'missing attribute definitions', () => {
 			it( 'does not crash when checking an attribute of a unregistered element', () => {
 				expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.false;
 			} );
@@ -1593,13 +1593,13 @@ describe( 'Schema', () => {
 			} );
 		} );
 
-		describe( 'missing types rules', () => {
+		describe( 'missing types definitions', () => {
 			it( 'does not crash when inheriting types of an unregistered element', () => {
 				schema.register( 'paragraph', {
 					inheritTypesFrom: '$block'
 				} );
 
-				expect( schema.getRule( 'paragraph' ) ).to.be.an( 'object' );
+				expect( schema.getDefinition( 'paragraph' ) ).to.be.an( 'object' );
 			} );
 		} );
 	} );
@@ -1607,7 +1607,7 @@ describe( 'Schema', () => {
 	describe( 'real scenarios', () => {
 		let r1bQi, r1i, r1lI, r1h, r1bQlI;
 
-		const rules = [
+		const definitions = [
 			() => {
 				schema.register( 'paragraph', {
 					inheritAllFrom: '$block'
@@ -1634,9 +1634,9 @@ describe( 'Schema', () => {
 				schema.on( 'checkChild', ( evt, args ) => {
 					const ctx = args[ 0 ];
 					const child = args[ 1 ];
-					const childRule = schema.getRule( child );
+					const childRule = schema.getDefinition( child );
 
-					if ( childRule.name == 'blockQuote' && ctx.matchEnd( 'blockQuote' ) ) {
+					if ( childRule.name == 'blockQuote' && ctx.endsWith( 'blockQuote' ) ) {
 						evt.stop();
 						evt.return = false;
 					}
@@ -1667,7 +1667,7 @@ describe( 'Schema', () => {
 					const ctx = args[ 0 ];
 					const attributeName = args[ 1 ];
 
-					if ( ctx.matchEnd( 'heading1 $text' ) && attributeName == 'bold' ) {
+					if ( ctx.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
 						evt.stop();
 						evt.return = false;
 					}
@@ -1692,20 +1692,20 @@ describe( 'Schema', () => {
 				allowIn: '$block'
 			} );
 
-			for ( const rule of rules ) {
-				rule();
+			for ( const definition of definitions ) {
+				definition();
 			}
 
 			// or...
 			//
-			// Use the below code to shuffle the rules.
+			// Use the below code to shuffle the definitions.
 			// Don't look here, Szymon!
 			//
-			// const rulesCopy = rules.slice();
+			// const definitionsCopy = definitions.slice();
 			//
-			// while ( rulesCopy.length ) {
-			// 	const r = Math.floor( Math.random() * rulesCopy.length );
-			// 	rulesCopy.splice( r, 1 )[ 0 ]();
+			// while ( definitionsCopy.length ) {
+			// 	const r = Math.floor( Math.random() * definitionsCopy.length );
+			// 	definitionsCopy.splice( r, 1 )[ 0 ]();
 			// }
 
 			root1 = new Element( '$root', null, [
@@ -2138,59 +2138,59 @@ describe( 'SchemaContext', () => {
 		} );
 	} );
 
-	describe( 'matchEnd()', () => {
+	describe( 'endsWith()', () => {
 		it( 'returns true if the end of the context matches the query - 1 item', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom', 'dom' ] );
 
-			expect( ctx.matchEnd( 'dom' ) ).to.be.true;
+			expect( ctx.endsWith( 'dom' ) ).to.be.true;
 		} );
 
 		it( 'returns true if the end of the context matches the query - 2 items', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom', 'dom' ] );
 
-			expect( ctx.matchEnd( 'bom dom' ) ).to.be.true;
+			expect( ctx.endsWith( 'bom dom' ) ).to.be.true;
 		} );
 
 		it( 'returns true if the end of the context matches the query - full match of 3 items', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom' ] );
 
-			expect( ctx.matchEnd( 'foo bar bom' ) ).to.be.true;
+			expect( ctx.endsWith( 'foo bar bom' ) ).to.be.true;
 		} );
 
 		it( 'returns true if the end of the context matches the query - full match of 1 items', () => {
 			const ctx = new SchemaContext( [ 'foo' ] );
 
-			expect( ctx.matchEnd( 'foo' ) ).to.be.true;
+			expect( ctx.endsWith( 'foo' ) ).to.be.true;
 		} );
 
 		it( 'returns true if not only the end of the context matches the query', () => {
 			const ctx = new SchemaContext( [ 'foo', 'foo', 'foo', 'foo' ] );
 
-			expect( ctx.matchEnd( 'foo foo' ) ).to.be.true;
+			expect( ctx.endsWith( 'foo foo' ) ).to.be.true;
 		} );
 
 		it( 'returns false if query matches the middle of the context', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom', 'dom' ] );
 
-			expect( ctx.matchEnd( 'bom' ) ).to.be.false;
+			expect( ctx.endsWith( 'bom' ) ).to.be.false;
 		} );
 
 		it( 'returns false if query matches the start of the context', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom', 'dom' ] );
 
-			expect( ctx.matchEnd( 'foo' ) ).to.be.false;
+			expect( ctx.endsWith( 'foo' ) ).to.be.false;
 		} );
 
 		it( 'returns false if query does not match', () => {
 			const ctx = new SchemaContext( [ 'foo', 'bar', 'bom', 'dom' ] );
 
-			expect( ctx.matchEnd( 'dom bar' ) ).to.be.false;
+			expect( ctx.endsWith( 'dom bar' ) ).to.be.false;
 		} );
 
 		it( 'returns false if query is longer than context', () => {
 			const ctx = new SchemaContext( [ 'foo' ] );
 
-			expect( ctx.matchEnd( 'bar', 'foo' ) ).to.be.false;
+			expect( ctx.endsWith( 'bar', 'foo' ) ).to.be.false;
 		} );
 	} );
 } );

+ 3 - 3
packages/ckeditor5-engine/tests/model/utils/deletecontent.js

@@ -471,19 +471,19 @@ describe( 'DataController utils', () => {
 						const attributeName = args[ 1 ];
 
 						// Allow 'a' and 'b' on paragraph>$text.
-						if ( ctx.matchEnd( 'paragraph $text' ) && [ 'a', 'b' ].includes( attributeName ) ) {
+						if ( ctx.endsWith( 'paragraph $text' ) && [ 'a', 'b' ].includes( attributeName ) ) {
 							evt.stop();
 							evt.return = true;
 						}
 
 						// Allow 'b' and 'c' in pchild>$text.
-						if ( ctx.matchEnd( 'pchild $text' ) && [ 'b', 'c' ].includes( attributeName ) ) {
+						if ( ctx.endsWith( 'pchild $text' ) && [ 'b', 'c' ].includes( attributeName ) ) {
 							evt.stop();
 							evt.return = true;
 						}
 
 						// Disallow 'c' on pchild>pchild>$text.
-						if ( ctx.matchEnd( 'pchild pchild $text' ) && attributeName == 'c' ) {
+						if ( ctx.endsWith( 'pchild pchild $text' ) && attributeName == 'c' ) {
 							evt.stop();
 							evt.return = false;
 						}

+ 6 - 6
packages/ckeditor5-engine/tests/model/utils/insertcontent.js

@@ -276,9 +276,9 @@ describe( 'DataController utils', () => {
 				model.schema.on( 'checkChild', ( evt, args ) => {
 					const ctx = args[ 0 ];
 					const child = args[ 1 ];
-					const childRule = model.schema.getRule( child );
+					const childRule = model.schema.getDefinition( child );
 
-					if ( childRule.name == 'paragraph' && ctx.matchEnd( '$root' ) ) {
+					if ( childRule.name == 'paragraph' && ctx.endsWith( '$root' ) ) {
 						evt.stop();
 						evt.return = false;
 					}
@@ -623,25 +623,25 @@ describe( 'DataController utils', () => {
 					const attributeName = args[ 1 ];
 
 					// Allow 'b' on paragraph>$text.
-					if ( ctx.matchEnd( 'paragraph $text' ) && attributeName == 'b' ) {
+					if ( ctx.endsWith( 'paragraph $text' ) && attributeName == 'b' ) {
 						evt.stop();
 						evt.return = true;
 					}
 
 					// Allow 'b' on paragraph>element>$text.
-					if ( ctx.matchEnd( 'paragraph element $text' ) && attributeName == 'b' ) {
+					if ( ctx.endsWith( 'paragraph element $text' ) && attributeName == 'b' ) {
 						evt.stop();
 						evt.return = true;
 					}
 
 					// Allow 'a' and 'b' on heading1>element>$text.
-					if ( ctx.matchEnd( 'heading1 element $text' ) && [ 'a', 'b' ].includes( attributeName ) ) {
+					if ( ctx.endsWith( 'heading1 element $text' ) && [ 'a', 'b' ].includes( attributeName ) ) {
 						evt.stop();
 						evt.return = true;
 					}
 
 					// Allow 'b' on element>table>td>$text.
-					if ( ctx.matchEnd( 'element table td $text' ) && attributeName == 'b' ) {
+					if ( ctx.endsWith( 'element table td $text' ) && attributeName == 'b' ) {
 						evt.stop();
 						evt.return = true;
 					}