Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 17 additions & 7 deletions packages/ckeditor5-list/src/list/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ export function reconvertItemsOnDataChange(
function collectListItemsToRefresh( listHead: ListElement, changedItems: Set<ModelNode> ) {
const itemsToRefresh = [];
const visited = new Set();
const stack: Array<ListItemAttributesMap> = [];
const stack: Array<{
modelAttributes: ListItemAttributesMap;
modelElement: ListElement;
}> = [];

for ( const { node, previous } of new SiblingListBlocksIterator( listHead ) ) {
if ( visited.has( node ) ) {
Expand All @@ -213,10 +216,13 @@ export function reconvertItemsOnDataChange(
}

// Update the stack for the current indent level.
stack[ itemIndent ] = Object.fromEntries(
Array.from( node.getAttributes() )
.filter( ( [ key ] ) => attributeNames.includes( key ) )
);
stack[ itemIndent ] = {
modelAttributes: Object.fromEntries(
Array.from( node.getAttributes() )
.filter( ( [ key ] ) => attributeNames.includes( key ) )
),
modelElement: node
};

// Find all blocks of the current node.
const blocks = getListItemBlocks( node, { direction: 'forward' } );
Expand Down Expand Up @@ -271,7 +277,10 @@ export function reconvertItemsOnDataChange(

function doesItemWrappingRequiresRefresh(
item: ModelElement,
stack: Array<ListItemAttributesMap>,
stack: Array<{
modelAttributes: ListItemAttributesMap;
modelElement: ListElement;
}>,
changedItems: Set<ModelNode>
) {
// Items directly affected by some "change" don't need a refresh, they will be converted by their own changes.
Expand All @@ -298,7 +307,8 @@ export function reconvertItemsOnDataChange(
const eventName = `checkAttributes:${ isListItemElement ? 'item' : 'list' }` as const;
const needsRefresh = listEditing.fire<ListEditingCheckAttributesEvent>( eventName, {
viewElement: element as ViewElement,
modelAttributes: stack[ indent ]
modelAttributes: stack[ indent ].modelAttributes,
modelReferenceElement: stack[ indent ].modelElement
} );

if ( needsRefresh ) {
Expand Down
1 change: 1 addition & 0 deletions packages/ckeditor5-list/src/list/listediting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ export type ListEditingCheckAttributesEvent = {
args: [ {
viewElement: ViewElement & { id?: string };
modelAttributes: ListItemAttributesMap;
modelReferenceElement: ListElement;
} ];
return: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ export class ListPropertiesEditing extends Plugin {
// Verify if the list view element (ul or ol) requires refreshing.
listEditing.on<ListEditingCheckAttributesEvent>(
'checkAttributes:list',
( evt, { viewElement, modelAttributes } ) => {
( evt, { viewElement, modelAttributes, modelReferenceElement } ) => {
for ( const strategy of strategies ) {
if ( !strategy.appliesToListItem( modelReferenceElement ) ) {
continue;
}

if ( strategy.getAttributeOnUpcast( viewElement ) != modelAttributes[ strategy.attributeName ] ) {
evt.return = true;
evt.stop();
Expand Down