Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ckeditor5-list/src/listformatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ function getSingleListItemConsistentFormat( model: Model, listItem: ModelElement
attributesToCheck.delete( attributeKey );
valuesMap[ attributeKey ] = undefined;
}
} else if ( !( attributeKey in valuesMap ) ) {
// Store it so a format would be removed when all items in the given list item does not allow that formatting.
valuesMap[ attributeKey ] = undefined;
}
}

Expand Down
57 changes: 56 additions & 1 deletion packages/ckeditor5-list/tests/listformatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Paragraph } from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import { Plugin } from '@ckeditor/ckeditor5-core/src/plugin.js';
import { BlockQuoteEditing } from '@ckeditor/ckeditor5-block-quote';
import { RemoveFormatEditing } from '@ckeditor/ckeditor5-remove-format';
import { CodeBlockEditing } from '@ckeditor/ckeditor5-code-block';
import { _setModelData, _getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
import { testUtils } from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';

Expand All @@ -26,7 +27,7 @@ describe( 'ListFormatting', () => {

beforeEach( async () => {
editor = await VirtualTestEditor.create( {
plugins: [ ListFormatting, Paragraph, BlockQuoteEditing, RemoveFormatEditing, MyPlugin, MyPlugin2 ]
plugins: [ ListFormatting, Paragraph, BlockQuoteEditing, CodeBlockEditing, RemoveFormatEditing, MyPlugin, MyPlugin2 ]
} );

model = editor.model;
Expand Down Expand Up @@ -393,6 +394,29 @@ describe( 'ListFormatting', () => {
);
} );

it( 'should not change attribute on formatted li if inserted inline object does not accept formatting', () => {
_setModelData( model,
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">foo[]</$text>' +
'</paragraph>'
);

model.schema.extend( 'inlineObject', {
disallowAttributes: 'inlineFormat'
} );

model.change( writer => {
writer.insert( writer.createElement( 'inlineObject' ), docSelection.getFirstPosition() );
} );

expect( _getModelData( model, { withoutSelection: true } ) ).to.equalMarkup(
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">foo</$text>' +
'<inlineObject></inlineObject>' +
'</paragraph>'
);
} );

it( 'should remove attribute from formatted li if inserted text has different format', () => {
_setModelData( model,
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
Expand Down Expand Up @@ -486,6 +510,37 @@ describe( 'ListFormatting', () => {
'</blockQuote>'
);
} );

it( 'should reset marker formatting when list item block changed to code block', () => {
_setModelData( model,
'<paragraph listIndent="0" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">fo[]o</$text>' +
'</paragraph>' +
'<paragraph listIndent="0" listItemId="b" listType="numbered">' +
'<$text inlineFormat="foo">bar</$text>' +
'</paragraph>'
);

expect( _getModelData( model, { withoutSelection: true } ) ).to.equalMarkup(
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">foo</$text>' +
'</paragraph>' +
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
'<$text inlineFormat="foo">bar</$text>' +
'</paragraph>'
);

editor.execute( 'codeBlock' );

expect( _getModelData( model, { withoutSelection: true } ) ).to.equalMarkup(
'<codeBlock language="plaintext" listIndent="0" listItemId="a" listType="numbered">' +
'foo' +
'</codeBlock>' +
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
'<$text inlineFormat="foo">bar</$text>' +
'</paragraph>'
);
} );
} );

describe( 'other elements handling (block objects, inline objects)', () => {
Expand Down