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

Commit

Permalink
Merge pull request #148 from ckeditor/t/147
Browse files Browse the repository at this point in the history
Fix: Default style's command will properly remove model element's attribute. Closes #147.
  • Loading branch information
Reinmar authored Oct 11, 2017
2 parents 11fff0b + 6e38fc1 commit c96fb19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/imagestyle/imagestylecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ export default class ImageStyleCommand extends Command {
doc.enqueueChanges( () => {
const batch = options.batch || doc.batch();

batch.setAttribute( imageElement, 'imageStyle', this.style.name );
// Default style means that there is no `imageStyle` attribute in the model.
// https://github.com/ckeditor/ckeditor5-image/issues/147
if ( this.style.isDefault ) {
batch.removeAttribute( imageElement, 'imageStyle' );
} else {
batch.setAttribute( imageElement, 'imageStyle', this.style.name );
}
} );
}
}
17 changes: 17 additions & 0 deletions tests/imagestyle/imagestylecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,21 @@ describe( 'ImageStyleCommand', () => {
expect( defaultStyleCommand.isEnabled ).to.be.false;
expect( otherStyleCommand.isEnabled ).to.be.false;
} );

it( 'default style should be active after executing it after another style', () => {
setData( document, '[<image></image>]' );

expect( defaultStyleCommand.value ).to.be.true;
expect( otherStyleCommand.value ).to.be.false;

otherStyleCommand.execute();

expect( getData( document ) ).to.equal( '[<image imageStyle="otherStyle"></image>]' );

defaultStyleCommand.execute();

expect( getData( document ) ).to.equal( '[<image></image>]' );
expect( defaultStyleCommand.value ).to.be.true;
expect( otherStyleCommand.value ).to.be.false;
} );
} );

0 comments on commit c96fb19

Please sign in to comment.