diff --git a/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts b/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts index ea1df7077df..859fb89f1ba 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/modelApi/common/retrieveModelFormatState.ts @@ -52,12 +52,17 @@ export function retrieveModelFormatState( // Segment formats segments?.forEach(segment => { if (isFirstSegment || segment.segmentType != 'SelectionMarker') { + const modelFormat = Object.assign({}, model.format); + delete modelFormat?.italic; + delete modelFormat?.underline; + delete modelFormat?.fontWeight; + retrieveSegmentFormat( formatState, isFirst, Object.assign( {}, - model.format, + modelFormat, block.format, block.decorator?.format, segment.format, diff --git a/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts b/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts index 135e32a41dd..d35344a4148 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/modelApi/common/retrieveModelFormatStateTest.ts @@ -708,6 +708,41 @@ describe('retrieveModelFormatState', () => { }); }); + it('With default format and other different format', () => { + const model = createContentModelDocument({ + fontFamily: 'Arial', + fontSize: '12px', + underline: true, + fontWeight: 'bold', + italic: true, + }); + const result: ContentModelFormatState = {}; + const para = createParagraph(); + const text1 = createText('test1', { fontFamily: 'Tahoma', fontSize: '15px' }); + para.segments.push(text1); + + text1.isSelected = true; + + spyOn(iterateSelections, 'iterateSelections').and.callFake((path, callback) => { + callback(path, undefined, para, [text1]); + return false; + }); + + retrieveModelFormatState(model, null, result); + + expect(result).toEqual({ + isBlockQuote: false, + isBold: false, + isSuperscript: false, + isSubscript: false, + fontSize: '11.25pt', + isCodeInline: false, + canUnlink: false, + canAddImageAltText: false, + fontName: 'Tahoma', + }); + }); + it('With default format and other different format', () => { const model = createContentModelDocument({ fontFamily: 'Arial',