From f50a6e578816f41481257df7cf524b8c6f6869bd Mon Sep 17 00:00:00 2001 From: "Julia Roldi (from Dev Box)" Date: Fri, 31 Jan 2025 16:15:54 -0300 Subject: [PATCH] auto format plugin --- .../lib/autoFormat/AutoFormatPlugin.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts index b47bc496fdc..34ebd01655c 100644 --- a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts @@ -114,6 +114,7 @@ export class AutoFormatPlugin implements EditorPlugin { const formatOptions: FormatContentModelOptions = { changeSource: '', apiName: '', + getChangeData: () => null, }; formatTextSegmentBeforeSelectionMarker( editor, @@ -147,11 +148,17 @@ export class AutoFormatPlugin implements EditorPlugin { } if (autoLink || autoTel || autoMailto) { - shouldLink = !!promoteLink(previousSegment, paragraph, { + const linkSegment = promoteLink(previousSegment, paragraph, { autoLink, autoTel, autoMailto, }); + const anchorNode = createAnchor( + linkSegment?.link?.format?.href || '', + linkSegment?.text || '' + ); + formatOptions.getChangeData = () => anchorNode; + shouldLink = !!linkSegment; if (shouldLink) { context.canUndoByBackspace = true; @@ -270,3 +277,10 @@ const getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink: ? ChangeSource.AutoLink : ''; }; + +const createAnchor = (url: string, text: string) => { + const anchor = document.createElement('a'); + anchor.href = url; + anchor.textContent = text; + return anchor; +};