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 + ); + }); });