diff --git a/apps/client/src/menus/electron_context_menu.ts b/apps/client/src/menus/electron_context_menu.ts index 90d6a4826..219a009c7 100644 --- a/apps/client/src/menus/electron_context_menu.ts +++ b/apps/client/src/menus/electron_context_menu.ts @@ -4,7 +4,7 @@ import zoomService from "../components/zoom.js"; import contextMenu, { type MenuItem } from "./context_menu.js"; import { t } from "../services/i18n.js"; import type { BrowserWindow } from "electron"; -import type { CommandNames } from "../components/app_context.js"; +import type { CommandNames, AppContext } from "../components/app_context.js"; function setupContextMenu() { const electron = utils.dynamicRequire("electron"); @@ -13,6 +13,8 @@ function setupContextMenu() { // FIXME: Remove typecast once Electron is properly integrated. const { webContents } = remote.getCurrentWindow() as BrowserWindow; + let appContext: AppContext; + webContents.on("context-menu", (event, params) => { const { editFlags } = params; const hasText = params.selectionText.trim().length > 0; @@ -119,6 +121,20 @@ function setupContextMenu() { uiIcon: "bx bx-search-alt", handler: () => electron.shell.openExternal(searchUrl) }); + + items.push({ + title: t("electron_context_menu.search_in_trilium", { term: shortenedSelection }), + uiIcon: "bx bx-search", + handler: async () => { + if (!appContext) { + appContext = (await import("../components/app_context.js")).default; + } + + await appContext.triggerCommand("searchNotes", { + searchString: params.selectionText + }); + } + }); } if (items.length === 0) { diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index d1f70699f..799c2a1d1 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1868,6 +1868,7 @@ "copy-link": "Copy link", "paste": "Paste", "paste-as-plain-text": "Paste as plain text", + "search_in_trilium": "Search for \"{{term}}\" in Trilium", "search_online": "Search for \"{{term}}\" with {{searchEngine}}" }, "image_context_menu": {