8
0
Просмотр исходного кода

Fix: Registered `$marker` element as an allowed `$root` and `$block` child.

Oskar Wróbel 7 лет назад
Родитель
Сommit
0c90591171

+ 8 - 0
packages/ckeditor5-engine/src/model/model.js

@@ -105,6 +105,14 @@ export default class Model {
 			isLimit: true
 		} );
 		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' ]
+		} );
 	}
 
 	/**

+ 22 - 9
packages/ckeditor5-engine/tests/conversion/upcast-converters.js

@@ -35,21 +35,14 @@ describe( 'upcast-helpers', () => {
 		schema = model.schema;
 
 		schema.extend( '$text', {
-			allowIn: '$root'
-		} );
-
-		schema.register( '$marker', {
-			inheritAllFrom: '$block'
+			allowIn: '$root',
+			allowAttributes: [ 'bold' ]
 		} );
 
 		schema.register( 'paragraph', {
 			inheritAllFrom: '$block'
 		} );
 
-		schema.extend( '$text', {
-			allowAttributes: [ 'bold' ]
-		} );
-
 		upcastDispatcher = new UpcastDispatcher( { schema } );
 		upcastDispatcher.on( 'text', convertText() );
 		upcastDispatcher.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
@@ -580,6 +573,26 @@ describe( 'upcast-helpers', () => {
 
 			expectResult( frag, 'foobar', marker );
 		} );
+
+		it( 'marker is in a block element', () => {
+			conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'paragraph', view: 'p' } ) );
+
+			const helper = upcastElementToMarker( { view: 'marker-search', model: 'search' } );
+
+			conversion.for( 'upcast' ).add( helper );
+
+			const element = new ViewContainerElement( 'p', null, [
+				new ViewText( 'fo' ),
+				new ViewUIElement( 'marker-search' ),
+				new ViewText( 'oba' ),
+				new ViewUIElement( 'marker-search' ),
+				new ViewText( 'r' )
+			] );
+
+			const marker = { name: 'search', start: [ 0, 2 ], end: [ 0, 5 ] };
+
+			expectResult( element, '<paragraph>foobar</paragraph>', marker );
+		} );
 	} );
 
 	function expectResult( viewToConvert, modelString, marker ) {

+ 6 - 0
packages/ckeditor5-engine/tests/model/model.js

@@ -50,6 +50,12 @@ describe( 'Model', () => {
 			expect( schema.checkChild( [ '$clipboardHolder' ], '$text' ) ).to.be.true;
 			expect( schema.checkChild( [ '$clipboardHolder' ], '$block' ) ).to.be.true;
 		} );
+
+		it( 'registers $marker to the schema', () => {
+			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;
+		} );
 	} );
 
 	describe( 'change() & enqueueChange()', () => {