Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 2d1d62f

Browse files
author
Piotr Jasiun
authored
Merge pull request #1319 from ckeditor/t/1317
Fix: Registered $marker element in Schema. Closes #1317.
2 parents 30dcf6c + 2ed35b9 commit 2d1d62f

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

src/model/model.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ export default class Model {
105105
isLimit: true
106106
} );
107107
this.schema.extend( '$text', { allowIn: '$clipboardHolder' } );
108+
109+
// Element needed by `upcastElementToMarker` converter.
110+
// This element temporarily represents marker bound during conversion process and is removed
111+
// at the end of conversion. `UpcastDispatcher` or at least `Conversion` class looks like a better for this
112+
// registration but both know nothing about Schema.
113+
this.schema.register( '$marker', {
114+
allowIn: [ '$root', '$block' ]
115+
} );
108116
}
109117

110118
/**

tests/conversion/upcast-converters.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,14 @@ describe( 'upcast-helpers', () => {
3535
schema = model.schema;
3636

3737
schema.extend( '$text', {
38-
allowIn: '$root'
39-
} );
40-
41-
schema.register( '$marker', {
42-
inheritAllFrom: '$block'
38+
allowIn: '$root',
39+
allowAttributes: [ 'bold' ]
4340
} );
4441

4542
schema.register( 'paragraph', {
4643
inheritAllFrom: '$block'
4744
} );
4845

49-
schema.extend( '$text', {
50-
allowAttributes: [ 'bold' ]
51-
} );
52-
5346
upcastDispatcher = new UpcastDispatcher( { schema } );
5447
upcastDispatcher.on( 'text', convertText() );
5548
upcastDispatcher.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
@@ -580,6 +573,26 @@ describe( 'upcast-helpers', () => {
580573

581574
expectResult( frag, 'foobar', marker );
582575
} );
576+
577+
it( 'marker is in a block element', () => {
578+
conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'paragraph', view: 'p' } ) );
579+
580+
const helper = upcastElementToMarker( { view: 'marker-search', model: 'search' } );
581+
582+
conversion.for( 'upcast' ).add( helper );
583+
584+
const element = new ViewContainerElement( 'p', null, [
585+
new ViewText( 'fo' ),
586+
new ViewUIElement( 'marker-search' ),
587+
new ViewText( 'oba' ),
588+
new ViewUIElement( 'marker-search' ),
589+
new ViewText( 'r' )
590+
] );
591+
592+
const marker = { name: 'search', start: [ 0, 2 ], end: [ 0, 5 ] };
593+
594+
expectResult( element, '<paragraph>foobar</paragraph>', marker );
595+
} );
583596
} );
584597

585598
function expectResult( viewToConvert, modelString, marker ) {

tests/manual/highlight.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class FancyWidget extends Plugin {
4949

5050
conversion.for( 'editingDowncast' ).add( downcastElementToElement( {
5151
model: 'fancywidget',
52-
view: ( modelItem, conversionApi ) => {
53-
const viewWriter = conversionApi.writer;
52+
view: ( modelItem, viewWriter ) => {
5453
const widgetElement = viewWriter.createContainerElement( 'figure', { class: 'fancy-widget' } );
5554
viewWriter.insert( ViewPosition.createAt( widgetElement ), viewWriter.createText( 'widget' ) );
5655

tests/model/model.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ describe( 'Model', () => {
5050
expect( schema.checkChild( [ '$clipboardHolder' ], '$text' ) ).to.be.true;
5151
expect( schema.checkChild( [ '$clipboardHolder' ], '$block' ) ).to.be.true;
5252
} );
53+
54+
it( 'registers $marker to the schema', () => {
55+
expect( schema.isRegistered( '$marker' ) ).to.be.true;
56+
expect( schema.checkChild( [ '$root' ], '$marker' ), 1 ).to.be.true;
57+
expect( schema.checkChild( [ '$block' ], '$marker' ), 1 ).to.be.true;
58+
} );
5359
} );
5460

5561
describe( 'change() & enqueueChange()', () => {

0 commit comments

Comments
 (0)