Search selected text in trilium (#7859)

This commit is contained in:
Elian Doran 2025-11-25 19:44:01 +02:00 committed by GitHub
commit d6de7cca96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import zoomService from "../components/zoom.js";
import contextMenu, { type MenuItem } from "./context_menu.js"; import contextMenu, { type MenuItem } from "./context_menu.js";
import { t } from "../services/i18n.js"; import { t } from "../services/i18n.js";
import type { BrowserWindow } from "electron"; import type { BrowserWindow } from "electron";
import type { CommandNames } from "../components/app_context.js"; import type { CommandNames, AppContext } from "../components/app_context.js";
function setupContextMenu() { function setupContextMenu() {
const electron = utils.dynamicRequire("electron"); const electron = utils.dynamicRequire("electron");
@ -13,6 +13,8 @@ function setupContextMenu() {
// FIXME: Remove typecast once Electron is properly integrated. // FIXME: Remove typecast once Electron is properly integrated.
const { webContents } = remote.getCurrentWindow() as BrowserWindow; const { webContents } = remote.getCurrentWindow() as BrowserWindow;
let appContext: AppContext;
webContents.on("context-menu", (event, params) => { webContents.on("context-menu", (event, params) => {
const { editFlags } = params; const { editFlags } = params;
const hasText = params.selectionText.trim().length > 0; const hasText = params.selectionText.trim().length > 0;
@ -119,6 +121,20 @@ function setupContextMenu() {
uiIcon: "bx bx-search-alt", uiIcon: "bx bx-search-alt",
handler: () => electron.shell.openExternal(searchUrl) 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) { if (items.length === 0) {

View File

@ -1868,6 +1868,7 @@
"copy-link": "Copy link", "copy-link": "Copy link",
"paste": "Paste", "paste": "Paste",
"paste-as-plain-text": "Paste as plain text", "paste-as-plain-text": "Paste as plain text",
"search_in_trilium": "Search for \"{{term}}\" in Trilium",
"search_online": "Search for \"{{term}}\" with {{searchEngine}}" "search_online": "Search for \"{{term}}\" with {{searchEngine}}"
}, },
"image_context_menu": { "image_context_menu": {