Skip to content

Commit

Permalink
Merge pull request #11597 from ckeditor/ck/11588
Browse files Browse the repository at this point in the history
Internal (style): The StyleCommand should be able to detect multiple inline styles applied. Closes #11588. Closes #11586.
  • Loading branch information
arkflpc authored Apr 8, 2022
2 parents 7e716d0 + 3aecb75 commit 24c15cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ckeditor5-style/src/stylecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ export default class StyleCommand extends Command {
* @param {module:engine/model/selection~Selection} selection
*/
_prepareNewInlineElementValue( value, selection ) {
let newValue = [];
let newValue = [ ...value ];

const attributes = selection.getAttributes();

for ( const [ attribute ] of attributes ) {
newValue = [ ...value, ...this._getAttributeValue( attribute ) ];
newValue = [ ...newValue, ...this._getAttributeValue( attribute ) ];
}

return newValue;
Expand Down
40 changes: 40 additions & 0 deletions packages/ckeditor5-style/tests/stylecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,46 @@ describe( 'StyleCommand', () => {
} );

describe( 'value', () => {
it( 'should detect applied inline style', () => {
setData( model, '<paragraph>[foobar]</paragraph>' );

model.change( writer => {
writer.setAttribute( 'htmlSpan', { classes: [ 'marker' ] }, root.getChild( 0 ).getChild( 0 ) );
} );

expect( command.value ).to.deep.equal( [ 'Marker' ] );
expect( getData( model ) ).to.equal(
'<paragraph>[<$text htmlSpan="{"classes":["marker"]}">foobar</$text>]</paragraph>'
);
} );

it( 'should detect applied multiple inline styles', () => {
setData( model, '<paragraph>[foobar]</paragraph>' );

model.change( writer => {
writer.setAttribute( 'htmlSpan', { classes: [ 'marker', 'typewriter' ] }, root.getChild( 0 ).getChild( 0 ) );
} );

expect( command.value ).to.deep.equal( [ 'Marker', 'Typewriter' ] );
expect( getData( model ) ).to.equal(
'<paragraph>[<$text htmlSpan="{"classes":["marker","typewriter"]}">foobar</$text>]</paragraph>'
);
} );

// https://github.com/ckeditor/ckeditor5/issues/11588
it( 'should detect applied multiple inline styles x', () => {
setData( model, '<paragraph>[foobar]</paragraph>' );

model.change( writer => {
writer.setAttribute( 'htmlSpan', { classes: [ 'marker' ] }, root.getChild( 0 ).getChild( 0 ) );
writer.setAttribute( 'bold', true, root.getChild( 0 ).getChild( 0 ) );
} );

expect( command.value ).to.deep.equal( [ 'Marker' ] );
expect( getData( model ) ).to.equal(
'<paragraph>[<$text bold="true" htmlSpan="{"classes":["marker"]}">foobar</$text>]</paragraph>'
);
} );
} );

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

0 comments on commit 24c15cb

Please sign in to comment.