diff --git a/package.json b/package.json index a038bd9d8f8..13384067187 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roosterjs", - "version": "7.2.3-darkmode.0", + "version": "7.2.5-darkmode.0", "description": "Framework-independent javascript editor", "repository": { "type": "git", diff --git a/packages/roosterjs-editor-plugins/lib/ContentEdit/features/autoLinkFeatures.ts b/packages/roosterjs-editor-plugins/lib/ContentEdit/features/autoLinkFeatures.ts index 5619c43fe2e..929f5628c18 100644 --- a/packages/roosterjs-editor-plugins/lib/ContentEdit/features/autoLinkFeatures.ts +++ b/packages/roosterjs-editor-plugins/lib/ContentEdit/features/autoLinkFeatures.ts @@ -92,12 +92,16 @@ function hasLinkBeforeCursor(event: PluginKeyboardEvent, editor: Editor): boolea function autoLink(event: PluginEvent, editor: Editor) { let anchor = editor.getDocument().createElement('a'); let linkData = cacheGetLinkData(event, editor); + + // Need to get searcher before we enter the async callback since the callback can happen when cursor is moved to next line + // and at that time a new searcher won't be able to find the link text to replace + let searcher = editor.getContentSearcherOfCursor(); anchor.textContent = linkData.originalUrl; anchor.href = linkData.normalizedUrl; editor.runAsync(() => { editor.performAutoComplete(() => { - replaceWithNode(editor, linkData.originalUrl, anchor, false /* exactMatch */); + replaceWithNode(editor, linkData.originalUrl, anchor, false /* exactMatch */, searcher); // The content at cursor has changed. Should also clear the cursor data cache clearContentSearcherCache(event); diff --git a/packages/roosterjs-editor-plugins/lib/HyperLink/HyperLink.ts b/packages/roosterjs-editor-plugins/lib/HyperLink/HyperLink.ts index fe9200d3f4d..c4f083032a2 100644 --- a/packages/roosterjs-editor-plugins/lib/HyperLink/HyperLink.ts +++ b/packages/roosterjs-editor-plugins/lib/HyperLink/HyperLink.ts @@ -14,12 +14,12 @@ export default class HyperLink implements EditorPlugin { * @param getTooltipCallback A callback function to get tooltip text for an existing hyperlink. * Default value is to return the href itself. If null, there will be no tooltip text. * @param target (Optional) Target window name for hyperlink. If null, will use "_blank" - * @param onLinkClick (Optional) Open link callback + * @param onLinkClick (Optional) Open link callback (return false to use default behavior) */ constructor( private getTooltipCallback: (href: string, a: HTMLAnchorElement) => string = href => href, private target?: string, - private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => void + private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => boolean | void ) {} /** @@ -73,8 +73,7 @@ export default class HyperLink implements EditorPlugin { ) as HTMLAnchorElement; if (anchor) { - if (this.onLinkClick) { - this.onLinkClick(anchor, event.rawEvent); + if (this.onLinkClick && this.onLinkClick(anchor, event.rawEvent) !== false) { return; } @@ -82,7 +81,8 @@ export default class HyperLink implements EditorPlugin { if ( !Browser.isFirefox && (href = this.tryGetHref(anchor)) && - (Browser.isMac ? event.rawEvent.metaKey : event.rawEvent.ctrlKey) + (Browser.isMac ? event.rawEvent.metaKey : event.rawEvent.ctrlKey) && + event.rawEvent.button === 0 ) { try { const target = this.target || '_blank';