mirror of
https://github.com/zadam/trilium.git
synced 2025-12-23 08:39:57 +01:00
chore(react/type_widgets): port and fix follow link under cursor
This commit is contained in:
@@ -11,6 +11,8 @@ import Component from "../../../components/component";
|
|||||||
import options from "../../../services/options";
|
import options from "../../../services/options";
|
||||||
import { loadIncludedNote, refreshIncludedNote } from "./utils";
|
import { loadIncludedNote, refreshIncludedNote } from "./utils";
|
||||||
import getTemplates, { updateTemplateCache } from "./snippets.js";
|
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:
|
* The editor can operate into two distinct modes:
|
||||||
@@ -88,7 +90,34 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
|
|||||||
editorApi: editorApiRef.current,
|
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 }) => {
|
useTriliumEvent("refreshIncludedNote", ({ noteId }) => {
|
||||||
|
|||||||
@@ -71,36 +71,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
resolve(this.watchdog.editor as CKTextEditor);
|
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) {
|
async createNoteForReferenceLink(title: string) {
|
||||||
if (!this.notePath) {
|
if (!this.notePath) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user