diff --git a/apps/client/src/menus/electron_context_menu.ts b/apps/client/src/menus/electron_context_menu.ts index 98435bb2d..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; @@ -124,7 +126,10 @@ function setupContextMenu() { title: t("electron_context_menu.search_in_trilium", { term: shortenedSelection }), uiIcon: "bx bx-search", handler: async () => { - const appContext = (await import("../components/app_context.js")).default; + if (!appContext) { + appContext = (await import("../components/app_context.js")).default; + } + await appContext.triggerCommand("searchNotes", { searchString: params.selectionText });