From 61693ea8582e7e8a1fbfda5856d515c22cba6934 Mon Sep 17 00:00:00 2001 From: "SOUTHAMERICA\\bvalverde" Date: Thu, 29 Feb 2024 15:02:26 -0600 Subject: [PATCH 1/4] init --- .../lib/publicApi/model/mergeModel.ts | 12 +++ .../test/publicApi/model/mergeModelTest.ts | 77 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts index 2a6621fa30f..6c5574a1fc3 100644 --- a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts +++ b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts @@ -343,6 +343,8 @@ function applyDefaultFormat( applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat' ) { group.blocks.forEach(block => { + mergeBlockFormat(applyDefaultFormatOption, block); + switch (block.blockType) { case 'BlockGroup': if (block.blockGroupType == 'ListItem') { @@ -384,6 +386,16 @@ function applyDefaultFormat( }); } +function mergeBlockFormat(applyDefaultFormatOption: string, block: ContentModelBlock) { + if ( + applyDefaultFormatOption == 'keepSourceEmphasisFormat' && + (block.blockType != 'BlockGroup' || block.blockGroupType != 'ListItem') && + block.format.backgroundColor + ) { + delete block.format.backgroundColor; + } +} + function mergeSegmentFormat( applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat', targetformat: ContentModelSegmentFormat, diff --git a/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts b/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts index 83e0c4112d6..5e86d703047 100644 --- a/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts +++ b/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts @@ -1784,6 +1784,83 @@ describe('mergeModel', () => { }); }); + it('Merge with keepSourceEmphasisFormat and remove background color of model', () => { + const MockedFormat = { + formatName: 'mocked', + fontWeight: 'ToBeRemoved', + italic: 'ToBeRemoved', + underline: 'ToBeRemoved', + } as any; + const majorModel = createContentModelDocument(MockedFormat); + const sourceModel: ContentModelDocument = { + blockGroupType: 'Document', + blocks: [ + { + blockType: 'Paragraph', + segments: [ + { + segmentType: 'Text', + text: 'test', + format: { + formatName: 'ToBeRemoved', + fontWeight: 'sourceFontWeight', + italic: true, + underline: true, + } as any, + }, + ], + format: { + backgroundColor: 'Test', + }, + }, + ], + }; + const para1 = createParagraph(); + const marker = createSelectionMarker(); + + para1.segments.push(marker); + majorModel.blocks.push(para1); + + const result = mergeModel( + majorModel, + sourceModel, + { newEntities: [], deletedEntities: [], newImages: [] }, + { + mergeFormat: 'keepSourceEmphasisFormat', + } + ); + + const paragraph: ContentModelParagraph = { + blockType: 'Paragraph', + segments: [ + { + segmentType: 'Text', + text: 'test', + format: { + formatName: 'mocked', + fontWeight: 'sourceFontWeight', + italic: true, + underline: true, + } as any, + }, + marker, + ], + format: {}, + }; + + expect(majorModel).toEqual({ + blockGroupType: 'Document', + blocks: [paragraph], + format: MockedFormat, + }); + expect(result).toEqual({ + marker, + paragraph, + path: [majorModel], + tableContext: undefined, + }); + }); + it('Merge model with List Item with default format, keep the source bold, italic and underline', () => { const MockedFormat = { formatName: 'mocked', From 264e5f3096b62adbeb9aafdf8d92c5410925d181 Mon Sep 17 00:00:00 2001 From: "SOUTHAMERICA\\bvalverde" Date: Thu, 29 Feb 2024 15:14:16 -0600 Subject: [PATCH 2/4] Remove unneeded code --- .../test/publicApi/model/mergeModelTest.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts b/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts index 5e86d703047..22b23e23948 100644 --- a/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts +++ b/packages-content-model/roosterjs-content-model-core/test/publicApi/model/mergeModelTest.ts @@ -1787,9 +1787,6 @@ describe('mergeModel', () => { it('Merge with keepSourceEmphasisFormat and remove background color of model', () => { const MockedFormat = { formatName: 'mocked', - fontWeight: 'ToBeRemoved', - italic: 'ToBeRemoved', - underline: 'ToBeRemoved', } as any; const majorModel = createContentModelDocument(MockedFormat); const sourceModel: ContentModelDocument = { @@ -1810,7 +1807,7 @@ describe('mergeModel', () => { }, ], format: { - backgroundColor: 'Test', + backgroundColor: 'ToBeRemoved', }, }, ], From 2f718eefc2360802b52274de1decd509295fe2a4 Mon Sep 17 00:00:00 2001 From: "SOUTHAMERICA\\bvalverde" Date: Fri, 1 Mar 2024 08:56:47 -0600 Subject: [PATCH 3/4] address comment --- .../lib/publicApi/model/mergeModel.ts | 6 +----- .../lib/format/ContentModelListItemFormat.ts | 4 +++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts index 6c5574a1fc3..02873e53733 100644 --- a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts +++ b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts @@ -387,11 +387,7 @@ function applyDefaultFormat( } function mergeBlockFormat(applyDefaultFormatOption: string, block: ContentModelBlock) { - if ( - applyDefaultFormatOption == 'keepSourceEmphasisFormat' && - (block.blockType != 'BlockGroup' || block.blockGroupType != 'ListItem') && - block.format.backgroundColor - ) { + if (applyDefaultFormatOption == 'keepSourceEmphasisFormat' && block.format.backgroundColor) { delete block.format.backgroundColor; } } diff --git a/packages-content-model/roosterjs-content-model-types/lib/format/ContentModelListItemFormat.ts b/packages-content-model/roosterjs-content-model-types/lib/format/ContentModelListItemFormat.ts index 8fdcd75c06d..f2d7b550b62 100644 --- a/packages-content-model/roosterjs-content-model-types/lib/format/ContentModelListItemFormat.ts +++ b/packages-content-model/roosterjs-content-model-types/lib/format/ContentModelListItemFormat.ts @@ -1,3 +1,4 @@ +import type { BackgroundColorFormat } from './formatParts/BackgroundColorFormat'; import type { DirectionFormat } from './formatParts/DirectionFormat'; import type { LineHeightFormat } from './formatParts/LineHeightFormat'; import type { ListStyleFormat } from './formatParts/ListStyleFormat'; @@ -15,4 +16,5 @@ export type ContentModelListItemFormat = DirectionFormat & PaddingFormat & TextAlignFormat & ListStyleFormat & - TextIndentFormat; + TextIndentFormat & + BackgroundColorFormat; From cb9fd57ed3113b534046abe923453551dbba67f8 Mon Sep 17 00:00:00 2001 From: "SOUTHAMERICA\\bvalverde" Date: Fri, 1 Mar 2024 09:00:47 -0600 Subject: [PATCH 4/4] remove empty line --- .../lib/publicApi/model/mergeModel.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts index 02873e53733..bb499451ad1 100644 --- a/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts +++ b/packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts @@ -344,7 +344,6 @@ function applyDefaultFormat( ) { group.blocks.forEach(block => { mergeBlockFormat(applyDefaultFormatOption, block); - switch (block.blockType) { case 'BlockGroup': if (block.blockGroupType == 'ListItem') {