From 7d1b32b6b786c28fedda1b510ceed2b9f3e3a27c Mon Sep 17 00:00:00 2001 From: Bryan Valverde U Date: Wed, 12 Jun 2024 10:28:04 -0600 Subject: [PATCH 1/2] Do not merge Hyperlink text color #2692 Co-authored-by: Jiuqing Song --- .../lib/modelApi/editing/mergeModel.ts | 39 ++++++++++++++++--- .../test/modelApi/editing/mergeModelTest.ts | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts b/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts index 94ed4f65319..df6639be10f 100644 --- a/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts +++ b/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts @@ -377,9 +377,9 @@ function applyDefaultFormat( }); if (segment.link) { - segment.link.format = mergeSegmentFormat( + segment.link.format = mergeLinkFormat( applyDefaultFormatOption, - getSegmentFormatInLinkFormat(format), + format, segment.link.format ); } @@ -400,16 +400,13 @@ function mergeBlockFormat(applyDefaultFormatOption: string, block: ReadonlyConte } /** - * Hyperlink format type definition only contains textColor, backgroundColor and underline. + * Hyperlink format type definition only contains backgroundColor and underline. * So create a minimum object with the styles supported in Hyperlink to be used in merge. */ function getSegmentFormatInLinkFormat( targetFormat: ContentModelSegmentFormat ): ContentModelSegmentFormat { const result: ContentModelHyperLinkFormat = {}; - if (targetFormat.textColor) { - result.textColor = targetFormat.textColor; - } if (targetFormat.backgroundColor) { result.backgroundColor = targetFormat.backgroundColor; } @@ -420,6 +417,28 @@ function getSegmentFormatInLinkFormat( return result; } +function mergeLinkFormat( + applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat', + targetFormat: ContentModelSegmentFormat, + sourceFormat: ContentModelHyperLinkFormat +) { + return applyDefaultFormatOption == 'mergeAll' + ? { ...getSegmentFormatInLinkFormat(targetFormat), ...sourceFormat } + : { + // Hyperlink segment format contains other attributes such as LinkFormat + // so we have to retain them + ...getFormatWithoutSegmentFormat(sourceFormat), + // Link format only have Text color, background color, Underline, but only + // text color + background color should be merged from the target + ...getSegmentFormatInLinkFormat(targetFormat), + // Get the semantic format of the source + ...getSemanticFormat(sourceFormat), + // The text color of the hyperlink should not be merged and + // we should always retain the source text color + ...getHyperlinkTextColor(sourceFormat), + }; +} + function mergeSegmentFormat( applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat', targetFormat: ContentModelSegmentFormat, @@ -465,3 +484,11 @@ function getFormatWithoutSegmentFormat( KeysOfSegmentFormat.forEach(key => delete resultFormat[key]); return resultFormat; } +function getHyperlinkTextColor(sourceFormat: ContentModelHyperLinkFormat) { + const result: ContentModelHyperLinkFormat = {}; + if (sourceFormat.textColor) { + result.textColor = sourceFormat.textColor; + } + + return result; +} diff --git a/packages/roosterjs-content-model-dom/test/modelApi/editing/mergeModelTest.ts b/packages/roosterjs-content-model-dom/test/modelApi/editing/mergeModelTest.ts index b22a2988f7b..72c4023c39e 100644 --- a/packages/roosterjs-content-model-dom/test/modelApi/editing/mergeModelTest.ts +++ b/packages/roosterjs-content-model-dom/test/modelApi/editing/mergeModelTest.ts @@ -3737,7 +3737,7 @@ describe('mergeModel', () => { anchorClass: 'bolt-link', borderRadius: '2px', textAlign: 'start', - textColor: '#000000', + textColor: 'var(--communication-foreground,rgba(0, 90, 158, 1))', underline: true, }, dataset: {}, From 8e16d3595040db3e87482813114900d30e58eaaf Mon Sep 17 00:00:00 2001 From: "SOUTHAMERICA\\bvalverde" Date: Wed, 12 Jun 2024 10:36:54 -0600 Subject: [PATCH 2/2] update versions.json --- versions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.json b/versions.json index 4739c19e0db..3d9721591dd 100644 --- a/versions.json +++ b/versions.json @@ -1,6 +1,6 @@ { "react": "8.56.0", - "main": "9.5.0", + "main": "9.5.1", "legacyAdapter": "8.62.0", "overrides": {} }