feat(theseus/ctxmenu): search-for-selection in page right-click menu

Adds a "Search for '<selection>'" item to the page context menu when
the user right-clicks with text selected. Uses SEARCH() so it honours
whichever engine the user has picked (Startpage default, or their own
via the picker), opens in a new foreground tab so the current page
isn't lost, and truncates the label at 40 chars so a long selection
doesn't stretch the menu. Ampersands in the label are doubled so
Chromium doesn't eat them as accelerator markers.
This commit is contained in:
Local Dev 2026-09-06 12:24:41 +02:00
parent debff9fc73
commit 7b3b5f7be8

13
main.js
View file

@ -1923,6 +1923,19 @@ function createTab(initial, opts = {}) {
}
if (p.isEditable) items.push({ role: "cut" }, { role: "copy" }, { role: "paste" }, { type: "separator" });
else if (p.selectionText) items.push({ role: "copy" }, { type: "separator" });
// "Search for …" when text is selected. Label uses a short excerpt so
// a long selection doesn't stretch the menu. Opens in a new foreground
// tab so the current page isn't lost — matches Chrome / Firefox UX.
if (p.selectionText) {
const raw = p.selectionText.replace(/\s+/g, " ").trim();
if (raw) {
const excerpt = raw.length > 40 ? raw.slice(0, 40) + "…" : raw;
items.push(
{ label: `Search for "${excerpt.replace(/&/g, "&&")}"`, click: () => createTab(SEARCH(raw)) },
{ type: "separator" },
);
}
}
items.push(
{ label: "Back", enabled: wc.navigationHistory.canGoBack(), click: () => wc.navigationHistory.goBack() },
{ label: "Forward", enabled: wc.navigationHistory.canGoForward(), click: () => wc.navigationHistory.goForward() },