Skip to content

Commit e09c2c5

Browse files
authored
Update the Entity's format when applying format on the content inside the Entity (#3196)
* Update the Entity's format when applying format on the content inside the Entity * fix test
1 parent ef7b998 commit e09c2c5

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ export function formatSegmentWithContentModel(
9292

9393
segmentAndParagraphs.forEach(item => {
9494
if (item[0].segmentType == 'Entity') {
95-
expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);
95+
expandEntitySelections(
96+
editor,
97+
item[0],
98+
formatsAndSegments,
99+
modelsFromEntities,
100+
item[1]
101+
);
96102
} else {
97103
formatsAndSegments.push([item[0].format, item[0], item[1]]);
98104
}
@@ -148,7 +154,8 @@ function expandEntitySelections(
148154
ShallowMutableContentModelSegment | null,
149155
ShallowMutableContentModelParagraph | null
150156
][],
151-
modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]
157+
modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][],
158+
paragraph: ShallowMutableContentModelParagraph | null
152159
) {
153160
const { id, entityType: type, isReadonly } = entity.entityFormat;
154161

@@ -185,6 +192,9 @@ function expandEntitySelections(
185192
modelsFromEntities.push([entity, root, model]);
186193
}
187194
});
195+
if (formattableRoots.length > 0) {
196+
formatsAndSegments.push([entity.format, entity, paragraph]);
197+
}
188198
}
189199
}
190200

packages/roosterjs-content-model-api/test/publicApi/utils/formatSegmentWithContentModelTest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ describe('formatSegmentWithContentModel', () => {
440440
{
441441
segmentType: 'Entity',
442442
blockType: 'Entity',
443-
format: {},
443+
format: {
444+
fontFamily: 'test',
445+
},
444446
entityFormat: { id: 'TestEntity1', entityType: 'TestEntity', isReadonly: true },
445447
wrapper: div,
446448
isSelected: true,
@@ -449,7 +451,7 @@ describe('formatSegmentWithContentModel', () => {
449451
});
450452
expect(formatContentModel).toHaveBeenCalledTimes(1);
451453
expect(formatResult).toBeTrue();
452-
expect(callback).toHaveBeenCalledTimes(1);
454+
expect(callback).toHaveBeenCalledTimes(2);
453455
expect(triggerEvent).toHaveBeenCalledTimes(1);
454456
expect(triggerEvent).toHaveBeenCalledWith('entityOperation', {
455457
entity: { id: 'TestEntity1', type: 'TestEntity', isReadonly: true, wrapper: div },

0 commit comments

Comments
 (0)