Skip to content

Commit

Permalink
Fix (indent): blockIndent now works with custom headings. Closes cked…
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Nov 13, 2020
1 parent 7d2c92c commit 2d90521
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ckeditor5-indent/src/indentblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export default class IndentBlock extends Plugin {
const indentCommand = editor.commands.get( 'indent' );
const outdentCommand = editor.commands.get( 'outdent' );

// Enable block indentation by default in paragraph and default headings.
const knownElements = [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];
// Enable block indentation to headging configuration options. If it is not defined enable in paragraph and default headings.
const options = editor.config.get( 'heading.options' );
const headings = options && options.map( option => option.model );
const knownElements = headings || [ 'paragraph', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6' ];

knownElements.forEach( elementName => {
if ( schema.isRegistered( elementName ) ) {
Expand Down
43 changes: 43 additions & 0 deletions packages/ckeditor5-indent/tests/indentblock-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,49 @@ describe( 'IndentBlock - integration', () => {
} );
} );

// https://github.com/ckeditor/ckeditor5/issues/8177
describe( 'with custom heading', () => {
beforeEach( () => {
return createTestEditor( {
plugins: [ Paragraph, HeadingEditing, IndentEditing, IndentBlock ],
indentBlock: { offset: 50, unit: 'px' },
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{
model: 'headingFancy',
view: {
name: 'h2',
classes: 'fancy'
},
title: 'Heading 2 (fancy)',
class: 'ck-heading_heading2_fancy',
converterPriority: 'high'
}
]
}
} ).then( newEditor => {
editor = newEditor;
doc = editor.model.document;
} );
} );

it( 'should work with custom (user defined) headings', () => {
editor.setData( '<h2 class="fancy" style="margin-left:150px">foo</h2>' );

const customHeading = doc.getRoot().getChild( 0 );

expect( customHeading.hasAttribute( 'blockIndent' ) ).to.be.true;
expect( customHeading.getAttribute( 'blockIndent' ) ).to.equal( '150px' );

expect( editor.getData() ).to.equal( '<h2 class="fancy" style="margin-left:150px;">foo</h2>' );
expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
.to.equal( '<h2 class="fancy" style="margin-left:150px">foo</h2>' );
} );
} );

// https://github.com/ckeditor/ckeditor5/issues/2359
it( 'should work with paragraphs regardless of plugin order', () => {
return createTestEditor( {
Expand Down

0 comments on commit 2d90521

Please sign in to comment.