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

Commit

Permalink
Merge branch 'master' into t/ckeditor5/733
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Feb 22, 2018
2 parents 3b4bb2e + 2d1d62f commit 4f52dc7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
} );
}

/**
Expand Down
31 changes: 22 additions & 9 deletions tests/conversion/upcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } );
Expand Down Expand Up @@ -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 ) {
Expand Down
3 changes: 1 addition & 2 deletions tests/manual/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class FancyWidget extends Plugin {

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

Expand Down
6 changes: 6 additions & 0 deletions tests/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 4f52dc7

Please sign in to comment.