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
feat(geo_map): add back open context menu
Elian Doran47b02da021d6
diff --git a/src/public/app/menus/link_context_menu.ts b/src/public/app/menus/link_context_menu.tsindex efa4da67ee..634f69db9a 100644--- a/src/public/app/menus/link_context_menu.ts+++ b/src/public/app/menus/link_context_menu.ts@@ -1,36 +1,44 @@import { t } from "../services/i18n.js";-import contextMenu, { type ContextMenuEvent } from "./context_menu.js";-import appContext from "../components/app_context.js";+import contextMenu, { type ContextMenuEvent, type MenuItem } from "./context_menu.js";+import appContext, { type CommandNames } from "../components/app_context.js";import type { ViewScope } from "../services/link.js";function openContextMenu(notePath: string, e: ContextMenuEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) {contextMenu.show({x: e.pageX,y: e.pageY,- items: [- { title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" },- { title: t("link_context_menu.open_note_in_new_split"), command: "openNoteInNewSplit", uiIcon: "bx bx-dock-right" },- { title: t("link_context_menu.open_note_in_new_window"), command: "openNoteInNewWindow", uiIcon: "bx bx-window-open" }- ],- selectMenuItemHandler: ({ command }) => {- if (!hoistedNoteId) {- hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;- }+ items: getItems(),+ selectMenuItemHandler: ({ command }) => handleLinkContextMenuItem(command, notePath, viewScope, hoistedNoteId)+ });+}++function getItems(): MenuItem<any>[] {+ return [+ { title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" },+ { title: t("link_context_menu.open_note_in_new_split"), command: "openNoteInNewSplit", uiIcon: "bx bx-dock-right" },+ { title: t("link_context_menu.open_note_in_new_window"), command: "openNoteInNewWindow", uiIcon: "bx bx-window-open" }+ ];+}- if (command === "openNoteInNewTab") {- appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });- } else if (command === "openNoteInNewSplit") {- const subContexts = appContext.tabManager.getActiveContext().getSubContexts();- const { ntxId } = subContexts[subContexts.length - 1];+function handleLinkContextMenuItem(command: string | undefined, notePath: string, viewScope = {}, hoistedNoteId: string | null = null) {+ if (!hoistedNoteId) {+ hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;+ }- appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });- } else if (command === "openNoteInNewWindow") {- appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId, viewScope });- }- }- });+ if (command === "openNoteInNewTab") {+ appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId, viewScope });+ } else if (command === "openNoteInNewSplit") {+ const subContexts = appContext.tabManager.getActiveContext().getSubContexts();+ const { ntxId } = subContexts[subContexts.length - 1];++ appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath, hoistedNoteId, viewScope });+ } else if (command === "openNoteInNewWindow") {+ appContext.triggerCommand("openInWindow", { notePath, hoistedNoteId, viewScope });+ }}export default {+ getItems,+ handleLinkContextMenuItem,openContextMenu};diff --git a/src/public/app/widgets/type_widgets/geo_map_context_menu.ts b/src/public/app/widgets/type_widgets/geo_map_context_menu.tsindex ef35f06e54..aae7746f7f 100644--- a/src/public/app/widgets/type_widgets/geo_map_context_menu.ts+++ b/src/public/app/widgets/type_widgets/geo_map_context_menu.ts@@ -1,18 +1,25 @@import appContext from "../../components/app_context.js";import type { ContextMenuEvent } from "../../menus/context_menu.js";import contextMenu from "../../menus/context_menu.js";+import linkContextMenu from "../../menus/link_context_menu.js";export default function openContextMenu(noteId: string, e: ContextMenuEvent) {contextMenu.show({x: e.pageX,y: e.pageY,items: [+ ...linkContextMenu.getItems(),+ { title: "----" },{ title: "Remove from map", command: "deleteFromMap", uiIcon: "bx bx-trash" }],selectMenuItemHandler: ({ command }) => {- if (command) {+ if (command === "deleteFromMap") {appContext.triggerCommand(command, { noteId });+ return;}++ // Pass the events to the link context menu+ linkContextMenu.handleLinkContextMenuItem(command, noteId);}});}