Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react/type_widgets): port and fix follow link under cursor
Elian Dorand443d796854a
diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsxindex 0a138c9635..dd0b48f85d 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, noteContexteditorApi: 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.tsindex 84760aedba..4678ef8304 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;