Skip to content

Commit

Permalink
Merge pull request #2701 from microsoft/u/juliaroldi/loops-link
Browse files Browse the repository at this point in the history
Fix auto link event in create link
  • Loading branch information
juliaroldi committed Jun 14, 2024
2 parents 33e3270 + cab30ec commit 2d95ac4
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { addLink, ChangeSource } from 'roosterjs-content-model-dom';
import { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';
import type { IEditor, LinkData } from 'roosterjs-content-model-types';
import type { ContentModelLink, IEditor, LinkData } from 'roosterjs-content-model-types';

/**
* @internal
*/
export function createLink(editor: IEditor) {
let anchorNode: Node | null = null;
const links: ContentModelLink[] = [];
formatTextSegmentBeforeSelectionMarker(
editor,
(_model, linkSegment, _paragraph) => {
if (linkSegment.link) {
links.push(linkSegment.link);
return true;
}
let linkData: LinkData | null = null;
Expand All @@ -22,15 +24,18 @@ export function createLink(editor: IEditor) {
},
dataset: {},
});
if (linkSegment.link) {
links.push(linkSegment.link);
}
return true;
}

return false;
},
{
changeSource: ChangeSource.AutoLink,
onNodeCreated: (_modelElement, node) => {
if (!anchorNode) {
onNodeCreated: (modelElement, node) => {
if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {
anchorNode = node;
}
},
Expand Down

0 comments on commit 2d95ac4

Please sign in to comment.