Skip to content

Commit

Permalink
Merge pull request #7711 from ckeditor/i/2358
Browse files Browse the repository at this point in the history
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. 
  • Loading branch information
pomek authored Jul 28, 2020
2 parents ebea184 + 437e29b commit 6b2cc25
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/ckeditor5-indent/src/indentblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ckeditor5-indent/tests/indentblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
} );
} );

Expand Down
10 changes: 9 additions & 1 deletion packages/ckeditor5-remove-format/src/removeformatcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 27 additions & 1 deletion packages/ckeditor5-remove-format/tests/removeformatcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand All @@ -45,6 +46,10 @@ describe( 'RemoveFormatCommand', () => {
model.schema.setAttributeProperties( 'bold', {
isFormatting: true
} );

model.schema.setAttributeProperties( 'someBlockFormatting', {
isFormatting: true
} );
} );
} );

Expand Down Expand Up @@ -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 )
}
};

Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 6b2cc25

Please sign in to comment.