Skip to content

Commit

Permalink
Merge pull request #9742 from ckeditor/i/5797
Browse files Browse the repository at this point in the history
Fix (engine): Updated `downcastwriter` to allow setting up attribute element's priority to 0. Closes #5797.
  • Loading branch information
mlewand authored May 25, 2021
2 parents 79454f8 + 3627a6b commit 7422073
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export function createViewElementFromHighlightDescriptor( writer, descriptor ) {
viewElement._addClass( descriptor.classes );
}

if ( descriptor.priority ) {
if ( typeof descriptor.priority === 'number' ) {
viewElement._priority = descriptor.priority;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-engine/src/view/downcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class DowncastWriter {
createAttributeElement( name, attributes, options = {} ) {
const attributeElement = new AttributeElement( this.document, name, attributes );

if ( options.priority ) {
if ( typeof options.priority === 'number' ) {
attributeElement._priority = options.priority;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/ckeditor5-engine/tests/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3513,6 +3513,15 @@ describe( 'downcast converters', () => {
expect( element.priority ).to.equal( 7 );
expect( element.hasClass( 'foo-class' ) ).to.be.true;
} );

it( 'should pass priority 0', () => {
const descriptor = {
priority: 0
};
const element = createViewElementFromHighlightDescriptor( viewWriter, descriptor );

expect( element.priority ).to.equal( 0 );
} );
} );
} );

Expand Down
6 changes: 6 additions & 0 deletions packages/ckeditor5-engine/tests/view/downcastwriter/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ describe( 'DowncastWriter', () => {
expect( element.id ).to.equal( 'bar' );
assertElementAttributes( element, attributes );
} );

it( 'should pass priority 0', () => {
const element = writer.createAttributeElement( 'foo', attributes, { priority: 0 } );

expect( element.priority ).to.equal( 0 );
} );
} );

describe( 'createContainerElement()', () => {
Expand Down

0 comments on commit 7422073

Please sign in to comment.