Explorar o código

Merge pull request #7711 from ckeditor/i/2358

Feature (indent): Block indentation should be recognized as a formatting attribute. Closes #2358.

Other (remove-format): Block formatting should be removed if the selection is inside that block.
Kamil Piechaczek %!s(int64=5) %!d(string=hai) anos
pai
achega
6b2cc25dd7

+ 2 - 0
packages/ckeditor5-indent/src/indentblock.js

@@ -88,6 +88,8 @@ export default class IndentBlock extends Plugin {
 			}
 		} );
 
+		schema.setAttributeProperties( 'blockIndent', { isFormatting: true } );
+
 		indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) );
 		outdentCommand.registerChildCommand( editor.commands.get( 'outdentBlock' ) );
 	}

+ 2 - 0
packages/ckeditor5-indent/tests/indentblock.js

@@ -44,6 +44,8 @@ describe( 'IndentBlock', () => {
 				expect( model.schema.checkAttribute( [ 'heading1' ], 'blockIndent' ) ).to.be.true;
 				expect( model.schema.checkAttribute( [ 'heading2' ], 'blockIndent' ) ).to.be.true;
 				expect( model.schema.checkAttribute( [ 'heading3' ], 'blockIndent' ) ).to.be.true;
+
+				expect( model.schema.getAttributeProperties( 'blockIndent' ) ).to.deep.equal( { isFormatting: true } );
 			} );
 	} );
 

+ 9 - 1
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;

+ 27 - 1
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: '<p someBlockFormatting="foo">f[oo</p><p>]bar</p>',
+				assert: () => expectEnabledPropertyToBe( true )
+			},
+
+			'state with block formatting (collapsed selection)': {
+				input: '<p someBlockFormatting="foo">f[]oo</p>',
+				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: '<p someBlockFormatting="foo">f[oo</p><p someBlockFormatting="bar">]bar</p>',
+				assert: () => expectModelToBeEqual( '<p>f[oo</p><p someBlockFormatting="bar">]bar</p>' )
+			},
+
+			'state with block formatting (collapsed selection)': {
+				input: '<p someBlockFormatting="foo">f[]oo</p><p someBlockFormatting="bar">bar</p>',
+				assert: () => expectModelToBeEqual( '<p>f[]oo</p><p someBlockFormatting="bar">bar</p>' )
 			}
+
 		};
 
 		generateTypicalUseCases( cases, {