From cf85be51a668963fa172785ee410c3c03c68fccf Mon Sep 17 00:00:00 2001 From: Bryan Valverde U Date: Thu, 29 Jun 2023 20:17:32 -0600 Subject: [PATCH] Check the link format segment to turnoff (#1928) --- .../lib/publicApi/segment/toggleUnderline.ts | 2 +- .../publicApi/segment/toggleUnderlineTest.ts | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/packages-content-model/roosterjs-content-model-editor/lib/publicApi/segment/toggleUnderline.ts b/packages-content-model/roosterjs-content-model-editor/lib/publicApi/segment/toggleUnderline.ts index b654b4e8bd8..39ffc055444 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/publicApi/segment/toggleUnderline.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/publicApi/segment/toggleUnderline.ts @@ -16,6 +16,6 @@ export default function toggleUnderline(editor: IContentModelEditor) { segment.link.format.underline = !!isTurningOn; } }, - format => !!format.underline + (format, segment) => !!format.underline || !!segment?.link?.format?.underline ); } diff --git a/packages-content-model/roosterjs-content-model-editor/test/publicApi/segment/toggleUnderlineTest.ts b/packages-content-model/roosterjs-content-model-editor/test/publicApi/segment/toggleUnderlineTest.ts index e994382322c..ca0b7e65c77 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/publicApi/segment/toggleUnderlineTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/publicApi/segment/toggleUnderlineTest.ts @@ -410,4 +410,64 @@ describe('toggleUnderline', () => { 1 ); }); + + it('Turn off link', () => { + runTest( + { + blockGroupType: 'Document', + blocks: [ + { + blockType: 'Paragraph', + segments: [ + { + segmentType: 'Text', + text: 'Test', + format: {}, + isSelected: true, + link: { + format: { + href: 'https://microsoft.github.io/roosterjs/index.html', + anchorTitle: 'asd', + underline: true, + }, + dataset: {}, + }, + }, + ], + format: {}, + }, + ], + format: {}, + }, + { + blockGroupType: 'Document', + blocks: [ + { + blockType: 'Paragraph', + segments: [ + { + segmentType: 'Text', + text: 'Test', + format: { + underline: false, + }, + isSelected: true, + link: { + format: { + href: 'https://microsoft.github.io/roosterjs/index.html', + anchorTitle: 'asd', + underline: false, + }, + dataset: {}, + }, + }, + ], + format: {}, + }, + ], + format: {}, + }, + 1 + ); + }); });