diff --git a/packages/ckeditor5-remove-format/src/removeformatcommand.js b/packages/ckeditor5-remove-format/src/removeformatcommand.js index 1deb8630cab..bd5fc648676 100644 --- a/packages/ckeditor5-remove-format/src/removeformatcommand.js +++ b/packages/ckeditor5-remove-format/src/removeformatcommand.js @@ -70,14 +70,22 @@ export default class RemoveFormatCommand extends Command { return !!first( this._getFormattingAttributes( item, schema ) ); }; + // Check formatting on selected items that are not blocks. for ( const curRange of selection.getRanges() ) { for ( const item of curRange.getItems() ) { - if ( itemHasRemovableFormatting( item ) ) { + if ( !schema.isBlock( item ) && itemHasRemovableFormatting( item ) ) { yield item; } } } + // Check formatting from selected blocks. + for ( const block of selection.getSelectedBlocks() ) { + if ( itemHasRemovableFormatting( block ) ) { + yield block; + } + } + // Finally the selection might be formatted as well, so make sure to check it. if ( itemHasRemovableFormatting( selection ) ) { yield selection; diff --git a/packages/ckeditor5-remove-format/tests/removeformatcommand.js b/packages/ckeditor5-remove-format/tests/removeformatcommand.js index 0604449e8d6..eb7f570fa2e 100644 --- a/packages/ckeditor5-remove-format/tests/removeformatcommand.js +++ b/packages/ckeditor5-remove-format/tests/removeformatcommand.js @@ -24,7 +24,8 @@ describe( 'RemoveFormatCommand', () => { editor.commands.add( 'removeFormat', command ); model.schema.register( 'p', { - inheritAllFrom: '$block' + inheritAllFrom: '$block', + allowAttributes: 'someBlockFormatting' } ); model.schema.addAttributeCheck( ( ctx, attributeName ) => { @@ -45,6 +46,10 @@ describe( 'RemoveFormatCommand', () => { model.schema.setAttributeProperties( 'bold', { isFormatting: true } ); + + model.schema.setAttributeProperties( 'someBlockFormatting', { + isFormatting: true + } ); } ); } ); @@ -94,6 +99,16 @@ describe( 'RemoveFormatCommand', () => { } }, assert: () => expectEnabledPropertyToBe( true ) + }, + + 'state with block formatting': { + input: '
f[oo
]bar
', + assert: () => expectEnabledPropertyToBe( true ) + }, + + 'state with block formatting (collapsed selection)': { + input: 'f[]oo
', + assert: () => expectEnabledPropertyToBe( true ) } }; @@ -140,7 +155,18 @@ describe( 'RemoveFormatCommand', () => { expect( model.document.selection.hasAttribute( 'bold' ) ).to.equal( false ); expect( model.document.selection.hasAttribute( 'irrelevant' ) ).to.equal( true ); } + }, + + 'state with block formatting': { + input: 'f[oo
]bar
', + assert: () => expectModelToBeEqual( 'f[oo
]bar
' ) + }, + + 'state with block formatting (collapsed selection)': { + input: 'f[]oo
bar
', + assert: () => expectModelToBeEqual( 'f[]oo
bar
' ) } + }; generateTypicalUseCases( cases, {