From b4161644d0e35802548fdcc507fa6fc803507ab7 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 18 Mar 2024 12:09:03 +0500 Subject: [PATCH] editor: handle link open on click --- .../editor/src/extensions/link/helpers/clickHandler.ts | 9 ++++++--- packages/editor/src/extensions/link/link.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/extensions/link/helpers/clickHandler.ts b/packages/editor/src/extensions/link/helpers/clickHandler.ts index 68795dd75..be5fc0689 100644 --- a/packages/editor/src/extensions/link/helpers/clickHandler.ts +++ b/packages/editor/src/extensions/link/helpers/clickHandler.ts @@ -17,12 +17,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { getAttributes } from "@tiptap/core"; +import { Editor, getAttributes } from "@tiptap/core"; import { MarkType } from "@tiptap/pm/model"; import { Plugin, PluginKey } from "@tiptap/pm/state"; type ClickHandlerOptions = { type: MarkType; + editor: Editor; }; export function clickHandler(options: ClickHandlerOptions): Plugin { @@ -50,10 +51,12 @@ export function clickHandler(options: ClickHandlerOptions): Plugin { const link = event.target as HTMLLinkElement; const href = link?.href ?? attrs.href; - const target = link?.target ?? attrs.target; + // const target = link?.target ?? attrs.target; if (link && href) { - if (view.editable) window.open(href, target); + if (view.editable) { + options.editor.storage.openLink?.(href); + } return true; } diff --git a/packages/editor/src/extensions/link/link.ts b/packages/editor/src/extensions/link/link.ts index 29263c647..4d351071f 100644 --- a/packages/editor/src/extensions/link/link.ts +++ b/packages/editor/src/extensions/link/link.ts @@ -273,7 +273,8 @@ export const Link = Mark.create({ if (this.options.openOnClick) { plugins.push( clickHandler({ - type: this.type + type: this.type, + editor: this.editor }) ); }