Skip to content

Commit cf0793d

Browse files
authored
Merge pull request #18812 from ckeditor/ck/18796
Internal (list): List marker formatting should be restored when removed with the remove-format feature.
2 parents 7028574 + b603df9 commit cf0793d

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

packages/ckeditor5-list/src/listformatting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export class ListFormatting extends Plugin {
112112
if (
113113
entry.attributeKey == 'listItemId' ||
114114
entry.attributeKey == 'listType' ||
115-
this._isInlineOrSelectionFormatting( entry.attributeKey )
115+
this._isInlineOrSelectionFormatting( entry.attributeKey ) ||
116+
Object.values( this._loadedFormatting ).includes( entry.attributeKey )
116117
) {
117118
if ( isListItemBlock( entry.range.start.nodeAfter ) ) {
118119
modifiedListItems.add( entry.range.start.nodeAfter );

packages/ckeditor5-list/tests/listformatting.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { VirtualTestEditor } from '@ckeditor/ckeditor5-core/tests/_utils/virtual
77
import { Paragraph } from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
88
import { Plugin } from '@ckeditor/ckeditor5-core/src/plugin.js';
99
import { BlockQuoteEditing } from '@ckeditor/ckeditor5-block-quote';
10+
import { RemoveFormatEditing } from '@ckeditor/ckeditor5-remove-format';
1011
import { _setModelData, _getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';
1112
import { testUtils } from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
1213

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

2627
beforeEach( async () => {
2728
editor = await VirtualTestEditor.create( {
28-
plugins: [ ListFormatting, Paragraph, BlockQuoteEditing, MyPlugin, MyPlugin2 ]
29+
plugins: [ ListFormatting, Paragraph, BlockQuoteEditing, RemoveFormatEditing, MyPlugin, MyPlugin2 ]
2930
} );
3031

3132
model = editor.model;
3233
docSelection = model.document.selection;
3334

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

3639
model.schema.register( 'blockObject', {
3740
inheritAllFrom: '$blockObject',
@@ -260,6 +263,76 @@ describe( 'ListFormatting', () => {
260263
'</paragraph>'
261264
);
262265
} );
266+
267+
describe( 'with remove-format feature', () => {
268+
it( 'should remove marker format when whole text format is removed', () => {
269+
_setModelData( model,
270+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
271+
'<$text inlineFormat="foo">[foo]</$text>' +
272+
'</paragraph>' +
273+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
274+
'<$text inlineFormat="foo">bar</$text>' +
275+
'</paragraph>'
276+
);
277+
278+
editor.execute( 'removeFormat' );
279+
280+
expect( _getModelData( model ) ).to.equalMarkup(
281+
'<paragraph listIndent="0" listItemId="a" listType="numbered">' +
282+
'[foo]' +
283+
'</paragraph>' +
284+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
285+
'<$text inlineFormat="foo">bar</$text>' +
286+
'</paragraph>'
287+
);
288+
} );
289+
290+
it( 'should remove marker format when part of text format is removed', () => {
291+
_setModelData( model,
292+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
293+
'<$text inlineFormat="foo">f[o]o</$text>' +
294+
'</paragraph>' +
295+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
296+
'<$text inlineFormat="foo">bar</$text>' +
297+
'</paragraph>'
298+
);
299+
300+
editor.execute( 'removeFormat' );
301+
302+
expect( _getModelData( model ) ).to.equalMarkup(
303+
'<paragraph listIndent="0" listItemId="a" listType="numbered">' +
304+
'<$text inlineFormat="foo">f</$text>' +
305+
'[o]' +
306+
'<$text inlineFormat="foo">o</$text>' +
307+
'</paragraph>' +
308+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
309+
'<$text inlineFormat="foo">bar</$text>' +
310+
'</paragraph>'
311+
);
312+
} );
313+
314+
it( 'should not remove marker format for a collapsed selection', () => {
315+
_setModelData( model,
316+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
317+
'<$text inlineFormat="foo">foo[]</$text>' +
318+
'</paragraph>' +
319+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
320+
'<$text inlineFormat="foo">bar</$text>' +
321+
'</paragraph>'
322+
);
323+
324+
editor.execute( 'removeFormat' );
325+
326+
expect( _getModelData( model ) ).to.equalMarkup(
327+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="a" listType="numbered">' +
328+
'<$text inlineFormat="foo">foo</$text>[]' +
329+
'</paragraph>' +
330+
'<paragraph listIndent="0" listItemFormat="foo" listItemId="b" listType="numbered">' +
331+
'<$text inlineFormat="foo">bar</$text>' +
332+
'</paragraph>'
333+
);
334+
} );
335+
} );
263336
} );
264337

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

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

855929
model.schema.extend( '$listItem', { allowAttributes: 'listItemFormat2' } );
930+
model.schema.setAttributeProperties( 'listItemFormat2', { isFormatting: true } );
856931
model.schema.addAttributeCheck( context => {
857932
const item = context.last;
858933
if ( !item.getAttribute( 'listItemId' ) ) {

0 commit comments

Comments
 (0)