mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 21:07:05 -06:00
chore(react/type_widgets): port and fix follow link under cursor
This commit is contained in:
parent
a975576214
commit
d443d79685
@ -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 }) => {
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user