From d443d796854ad7b5db33cf8d94e7fc4ed58951fa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 25 Sep 2025 14:35:52 +0300 Subject: [PATCH] chore(react/type_widgets): port and fix follow link under cursor --- .../type_widgets/text/EditableText.tsx | 31 ++++++++++++++++++- .../widgets/type_widgets_old/editable_text.ts | 30 ------------------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx index 0a138c963..dd0b48f85 100644 --- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx +++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx @@ -11,6 +11,8 @@ import Component from "../../../components/component"; import options from "../../../services/options"; import { loadIncludedNote, refreshIncludedNote } from "./utils"; import getTemplates, { updateTemplateCache } from "./snippets.js"; +import appContext from "../../../components/app_context"; +import link, { parseNavigationStateFromUrl } from "../../../services/link"; /** * The editor can operate into two distinct modes: @@ -88,7 +90,34 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext editorApi: editorApiRef.current, }); }, - loadIncludedNote + loadIncludedNote, + async followLinkUnderCursorCommand() { + const editor = await waitForEditor(); + const selection = editor?.model.document.selection; + const selectedElement = selection?.getSelectedElement(); + + if (selectedElement?.name === "reference") { + const { notePath } = parseNavigationStateFromUrl(selectedElement.getAttribute("href") as string | undefined); + + if (notePath) { + await appContext.tabManager.getActiveContext()?.setNote(notePath); + return; + } + } + + if (!selection?.hasAttribute("linkHref")) { + return; + } + + const selectedLinkUrl = selection.getAttribute("linkHref") as string; + const notePath = link.getNotePathFromUrl(selectedLinkUrl); + + if (notePath) { + await appContext.tabManager.getActiveContext()?.setNote(notePath); + } else { + window.open(selectedLinkUrl, "_blank"); + } + } }); useTriliumEvent("refreshIncludedNote", ({ noteId }) => { diff --git a/apps/client/src/widgets/type_widgets_old/editable_text.ts b/apps/client/src/widgets/type_widgets_old/editable_text.ts index 84760aedb..4678ef830 100644 --- a/apps/client/src/widgets/type_widgets_old/editable_text.ts +++ b/apps/client/src/widgets/type_widgets_old/editable_text.ts @@ -71,36 +71,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { resolve(this.watchdog.editor as CKTextEditor); } - async followLinkUnderCursorCommand() { - await this.initialized; - - const selection = this.watchdog.editor?.model.document.selection; - const selectedElement = selection?.getSelectedElement(); - - if (selectedElement?.name === "reference") { - // reference link - const notePath = selectedElement.getAttribute("notePath") as string | undefined; - - if (notePath) { - await appContext.tabManager.getActiveContext()?.setNote(notePath); - return; - } - } - - if (!selection?.hasAttribute("linkHref")) { - return; - } - - const selectedLinkUrl = selection.getAttribute("linkHref") as string; - const notePath = link.getNotePathFromUrl(selectedLinkUrl); - - if (notePath) { - await appContext.tabManager.getActiveContext()?.setNote(notePath); - } else { - window.open(selectedLinkUrl, "_blank"); - } - } - async createNoteForReferenceLink(title: string) { if (!this.notePath) { return;