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: 2 additions & 1 deletion packages/ckeditor5-list/src/listformatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class ListFormatting extends Plugin {
if (
entry.attributeKey == 'listItemId' ||
entry.attributeKey == 'listType' ||
this._isInlineOrSelectionFormatting( entry.attributeKey )
this._isInlineOrSelectionFormatting( entry.attributeKey ) ||
Object.values( this._loadedFormatting ).includes( entry.attributeKey )
) {
if ( isListItemBlock( entry.range.start.nodeAfter ) ) {
modifiedListItems.add( entry.range.start.nodeAfter );
Expand Down
77 changes: 76 additions & 1 deletion packages/ckeditor5-list/tests/listformatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { VirtualTestEditor } from '@ckeditor/ckeditor5-core/tests/_utils/virtual
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 { _setModelData, _getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
import { testUtils } from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';

Expand All @@ -25,13 +26,15 @@ describe( 'ListFormatting', () => {

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

model = editor.model;
docSelection = model.document.selection;

model.schema.extend( '$text', { allowAttributes: [ 'inlineFormat', 'inlineFormat2' ] } );
model.schema.setAttributeProperties( 'inlineFormat', { isFormatting: true } );
model.schema.setAttributeProperties( 'inlineFormat2', { isFormatting: true } );

model.schema.register( 'blockObject', {
inheritAllFrom: '$blockObject',
Expand Down Expand Up @@ -260,6 +263,76 @@ describe( 'ListFormatting', () => {
'</paragraph>'
);
} );

describe( 'with remove-format feature', () => {
it( 'should remove marker format when whole text format is removed', () => {
_setModelData( model,
'<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( 'removeFormat' );

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

it( 'should remove marker format when part of text format is removed', () => {
_setModelData( model,
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">f[o]o</$text>' +
'</paragraph>' +
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
'<$text inlineFormat="foo">bar</$text>' +
'</paragraph>'
);

editor.execute( 'removeFormat' );

expect( _getModelData( model ) ).to.equalMarkup(
'<paragraph listIndent="0" listItemId="a" listType="numbered">' +
'<$text inlineFormat="foo">f</$text>' +
'[o]' +
'<$text inlineFormat="foo">o</$text>' +
'</paragraph>' +
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
'<$text inlineFormat="foo">bar</$text>' +
'</paragraph>'
);
} );

it( 'should not remove marker format for a collapsed selection', () => {
_setModelData( model,
'<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( 'removeFormat' );

expect( _getModelData( model ) ).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>'
);
} );
} );
} );

describe( 'inserting a text node into a list item', () => {
Expand Down Expand Up @@ -833,6 +906,7 @@ describe( 'ListFormatting', () => {
const model = this.editor.model;

model.schema.extend( '$listItem', { allowAttributes: 'listItemFormat' } );
model.schema.setAttributeProperties( 'listItemFormat', { isFormatting: true } );
model.schema.addAttributeCheck( context => {
const item = context.last;
if ( !item.getAttribute( 'listItemId' ) ) {
Expand All @@ -853,6 +927,7 @@ describe( 'ListFormatting', () => {
const model = this.editor.model;

model.schema.extend( '$listItem', { allowAttributes: 'listItemFormat2' } );
model.schema.setAttributeProperties( 'listItemFormat2', { isFormatting: true } );
model.schema.addAttributeCheck( context => {
const item = context.last;
if ( !item.getAttribute( 'listItemId' ) ) {
Expand Down