浏览代码

Internal: Allowed $marker element in any parent element.

Oskar Wróbel 6 年之前
父节点
当前提交
2cd96cfdb9
共有 2 个文件被更改,包括 16 次插入8 次删除
  1. 9 6
      packages/ckeditor5-engine/src/model/model.js
  2. 7 2
      packages/ckeditor5-engine/tests/model/model.js

+ 9 - 6
packages/ckeditor5-engine/src/model/model.js

@@ -103,12 +103,15 @@ export default class Model {
 		} );
 		this.schema.extend( '$text', { allowIn: '$clipboardHolder' } );
 
-		// Element needed by `upcastElementToMarker` converter.
-		// This element temporarily represents marker bound during conversion process and is removed
-		// at the end of conversion. `UpcastDispatcher` or at least `Conversion` class looks like a better for this
-		// registration but both know nothing about Schema.
-		this.schema.register( '$marker', {
-			allowIn: [ '$root', '$block' ]
+		// An element needed by the `upcastElementToMarker` converter.
+		// This element temporarily represents marker bound during the conversion process and is removed
+		// at the end of the conversion. `UpcastDispatcher` or at least `Conversion` class looks like a
+		// better place for this registration but both know nothing about the Schema.
+		this.schema.register( '$marker' );
+		this.schema.addChildCheck( ( context, childDefinition ) => {
+			if ( childDefinition.name === '$marker' ) {
+				return true;
+			}
 		} );
 
 		injectSelectionPostFixer( this );

+ 7 - 2
packages/ckeditor5-engine/tests/model/model.js

@@ -51,9 +51,14 @@ describe( 'Model', () => {
 		} );
 
 		it( 'registers $marker to the schema', () => {
+			model.document.createRoot( '$anywhere', 'anywhere' );
+			schema.register( 'anything' );
+
 			expect( schema.isRegistered( '$marker' ) ).to.be.true;
-			expect( schema.checkChild( [ '$root' ], '$marker' ), 1 ).to.be.true;
-			expect( schema.checkChild( [ '$block' ], '$marker' ), 1 ).to.be.true;
+			expect( schema.checkChild( [ '$root' ], '$marker' ) ).to.be.true;
+			expect( schema.checkChild( [ '$block' ], '$marker' ) ).to.be.true;
+			expect( schema.checkChild( [ '$anywhere' ], '$marker' ) ).to.be.true;
+			expect( schema.checkChild( [ 'anything' ], '$marker' ) ).to.be.true;
 		} );
 	} );