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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const handleList: ContentModelBlockHandler<ContentModelListItem> = (
itemLevel.format.listStyleType != stackLevel.format?.listStyleType)
) {
break;
} else if (itemLevel.listType == 'UL') {
// Apply metadata to list level to make sure list style is correct after rendering
applyMetadata(itemLevel, context.metadataAppliers.listLevel, itemLevel.format, context);
Comment on lines +47 to +48
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling applyMetadata inside the reuse loop uses the current context.listFormat.nodeStack length to determine list depth (see listLevelMetadataApplier computes depth = nodeStack.length - 2). During the reuse loop, nodeStack still includes the full stack depth, so applying metadata for layer 0/1/... will use the deepest depth for every call, producing incorrect listStyleType for nested lists. Consider temporarily adjusting nodeStack to the current layer depth when applying metadata (or otherwise passing the correct depth), and consider applying this for OL as well if metadata can affect ordered list styles.

Suggested change
// Apply metadata to list level to make sure list style is correct after rendering
applyMetadata(itemLevel, context.metadataAppliers.listLevel, itemLevel.format, context);
// Apply metadata to list level to make sure list style is correct after rendering.
// Temporarily adjust nodeStack length so depth-dependent metadata is computed correctly
const originalLength = nodeStack.length;
try {
// nodeStack[0] is the parent, nodeStack[layer + 1] is the current list level
nodeStack.length = layer + 2;
applyMetadata(
itemLevel,
context.metadataAppliers.listLevel,
itemLevel.format,
context
);
} finally {
nodeStack.length = originalLength;
}

Copilot uses AI. Check for mistakes.
}

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as applyFormat from '../../../lib/modelToDom/utils/applyFormat';
import * as applyMetadata from '../../../lib/modelToDom/utils/applyMetadata';
import * as reuseCachedElement from '../../../lib/domUtils/reuseCachedElement';
import { BulletListType } from '../../../lib/constants/BulletListType';
import { ContentModelListItem, ModelToDomContext } from 'roosterjs-content-model-types';
Expand Down Expand Up @@ -612,6 +614,96 @@ describe('handleList handles metadata', () => {
});
expect(listItem.levels[0].format.listStyleType).toBe('disc');
});

it('List style type should be changed by metadata when there is existing UL to reuse', () => {
const listItem: ContentModelListItem = {
blockType: 'BlockGroup',
blockGroupType: 'ListItem',
blocks: [
{
blockType: 'Paragraph',
segments: [
{
segmentType: 'Br',
format: {},
},
],
format: {},
},
],
levels: [
{
listType: 'UL',
format: {},
dataset: {
editingInfo: '{"applyListStyleFromLevel":true}',
},
},
],
formatHolder: {
segmentType: 'SelectionMarker',
isSelected: false,
format: {},
},
format: {},
};

context = createModelToDomContext(undefined, {
metadataAppliers: {
listLevel: listLevelMetadataApplier,
},
});

const existingUL = document.createElement('ul');
context.listFormat.nodeStack = [
{
node: parent,
refNode: null,
},
{
node: existingUL,
listType: 'UL',
dataset: {
editingInfo: '{"applyListStyleFromLevel":true}',
},
format: {},
refNode: null,
},
];

const applyFormatSpy = spyOn(applyFormat, 'applyFormat').and.callThrough();
const applyMetadataSpy = spyOn(applyMetadata, 'applyMetadata').and.callThrough();

handleList(document, parent, listItem, context, null);

expect(applyMetadataSpy).toHaveBeenCalledTimes(1);
expect(applyMetadataSpy).toHaveBeenCalledWith(
listItem.levels[0],
context.metadataAppliers.listLevel as any,
listItem.levels[0].format,
context
);
expect(applyFormatSpy).not.toHaveBeenCalled();

expectHtml(parent.outerHTML, ['<div></div>']);
expect(context.listFormat).toEqual({
threadItemCounts: [],
nodeStack: [
{
node: parent,
refNode: null,
},
{
node: existingUL,
listType: 'UL',
dataset: { editingInfo: '{"applyListStyleFromLevel":true}' },
format: {},
refNode: null,
},
],
});
expect(listItem.levels[0].format.listStyleType).toBe('disc');
});
Comment on lines +618 to +706
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new reuse-path test only covers a single-level UL. Since listLevelMetadataApplier derives list style from list depth, adding a nested-list reuse test (multiple levels in nodeStack/levels) would help catch depth-related regressions in the new applyMetadata-on-reuse logic.

Copilot uses AI. Check for mistakes.
});

describe('handleList with cache', () => {
Expand Down
Loading