fix(web,desktop): unify themed context menus with icons, warning tones, and text actions #7998
Closedbberka(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/7998/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/contextMenuFallback.ts line 585OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -473,0 +565,21 @@565+ * and presents the styled HTML context menu (Cut, Copy, Paste, Select all).566+ */567+export function installGlobalTextContextMenu(): () => void {568+ if (typeof window === "undefined") {569+ return () => undefined;570+ }571+572+ const handleContextMenu = (event: MouseEvent) => {573+ // If another handler already called preventDefault(), do not intercept.574+ if (event.defaultPrevented) {575+ return;576+ }577+578+ const target = event.target;579+ const isInputElement =580+ target instanceof HTMLInputElement &&581+ !["hidden", "file", "checkbox", "radio", "button", "submit", "reset", "image"].includes(582+ target.type,583+ );584+ const isTextAreaElement = target instanceof HTMLTextAreaElement;585+ const isContentEditable = target instanceof HTMLElement && target.isContentEditable;@@ -36,7 +36,4 @@3636 items: readonly ContextMenuItem<T>[],3737 position?: { x: number; y: number },3838 ): Promise<T | null> => {39- if (window.desktopBridge) {40- return window.desktopBridge.showContextMenu(items, position) as Promise<T | null>;41- }4239 return showContextMenuFallback(items, position);apps/web/src/contextMenuFallback.ts lines 579 to 583OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -473,0 +563,21 @@563+ * Installs a global context menu listener that captures unhandled right-clicks564+ * on text inputs, textareas, contenteditable elements, or selected text,565+ * and presents the styled HTML context menu (Cut, Copy, Paste, Select all).566+ */567+export function installGlobalTextContextMenu(): () => void {568+ if (typeof window === "undefined") {569+ return () => undefined;570+ }571+572+ const handleContextMenu = (event: MouseEvent) => {573+ // If another handler already called preventDefault(), do not intercept.574+ if (event.defaultPrevented) {575+ return;576+ }577+578+ const target = event.target;579+ const isInputElement =580+ target instanceof HTMLInputElement &&581+ !["hidden", "file", "checkbox", "radio", "button", "submit", "reset", "image"].includes(582+ target.type,583+ );
- apps/web/src/contextMenuFallback.ts line 698Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -473,0 +602,21 @@602+ hasInputSelection = end > start;603+ } catch {604+ hasInputSelection = false;605+ }606+ hasValue = input.value.length > 0;607+ } else if (isContentEditable && target instanceof HTMLElement) {608+ hasValue = (target.textContent ?? "").length > 0;609+ }610+611+ const hasSelection = isEditable612+ ? isInputElement || isTextAreaElement613+ ? hasInputSelection614+ : hasWindowSelection615+ : hasWindowSelection;616+617+ // Only show our menu if right-clicking an editable element OR there is text selected.618+ if (!isEditable && !hasSelection) {619+ return;620+ }621+622+ event.preventDefault();apps/web/src/contextMenuFallback.ts line 810Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -473,0 +710,21 @@710+ const text = input.value.slice(input.selectionStart ?? 0, input.selectionEnd ?? 0);711+ if (text) {712+ try {713+ await navigator.clipboard.writeText(text);714+ } catch {715+ document.execCommand("copy");716+ }717+ }718+ } catch {719+ document.execCommand("copy");720+ }721+ } else {722+ const text = selection?.toString() ?? "";723+ if (text) {724+ try {725+ await navigator.clipboard.writeText(text);726+ } catch {727+ document.execCommand("copy");728+ }729+ }730+ }
- apps/web/src/contextMenuFallback.ts lines 176 to 185OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -122,3 +166,20 @@166+ {167+ tag: "path",168+ attrs: { d: "M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11" },169+ },170+ ],122171 };123172124-function createIconElement(name: string, tone: "neutral" | "destructive"): SVGSVGElement | null {173+export type ContextMenuTone = "neutral" | "destructive" | "warning";174+175+export function resolveItemTone<T extends string>(item: ContextMenuItem<T>): ContextMenuTone {176+ if (item.destructive === true || item.id === "delete") {177+ return "destructive";178+ }179+ if (item.tone === "warning" || item.id === "archive") {180+ return "warning";181+ }182+ if (item.tone === "destructive") {183+ return "destructive";184+ }185+ return "neutral";@@ -473,0 +602,21 @@602+ hasInputSelection = end > start;603+ } catch {604+ hasInputSelection = false;605+ }606+ hasValue = input.value.length > 0;607+ } else if (isContentEditable && target instanceof HTMLElement) {608+ hasValue = (target.textContent ?? "").length > 0;609+ }610+611+ const hasSelection = isEditable612+ ? isInputElement || isTextAreaElement613+ ? hasInputSelection614+ : hasWindowSelection615+ : hasWindowSelection;616+617+ // Only show our menu if right-clicking an editable element OR there is text selected.618+ if (!isEditable && !hasSelection) {619+ return;620+ }621+622+ event.preventDefault();apps/web/src/contextMenuFallback.ts lines 414 to 414OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -335,4 +411,4 @@335411 }336412337413 if (typeof item.icon === "string") {338- const icon = createIconElement(item.icon, isLeafDestructive ? "destructive" : "neutral");414+ const icon = createIconElement(item.icon, itemTone);apps/web/src/contextMenuFallback.ts lines 353 to 354OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -278,4 +351,4 @@278351 menu.className =279352 "dropdown-glass fixed z-[10000] min-w-32 max-w-sm overflow-hidden rounded-lg bg-clip-padding text-popover-foreground outline-none";280353 menu.style.cssText =281- "position:fixed;z-index:10000;min-width:8rem;max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--contrast-popover-foreground);outline:none;pointer-events:auto;";354+ "position:fixed;z-index:10000;min-width:8rem;max-width:24rem;overflow:hidden;border-radius:var(--radius-lg);background-clip:padding-box;color:var(--contrast-popover-foreground);background:color-mix(in srgb, var(--popover) 18%, color-mix(in srgb, var(--popover) var(--glass-opacity,80%), transparent));-webkit-backdrop-filter:blur(var(--glass-blur,12px)) saturate(var(--glass-saturation,1.14));backdrop-filter:blur(var(--glass-blur,12px)) saturate(var(--glass-saturation,1.14));border:1px solid color-mix(in srgb, var(--contrast-foreground) 10%, transparent);box-shadow:0 16px 40px -18px rgb(0 0 0 / 55%);outline:none;pointer-events:auto;";
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/components/threadActionMenu.logic.ts lines 132 to 132OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -128,3 +129,4 @@128129 id: "archive",129130 label: "Archive thread",130131 icon: "archive",132+ tone: "warning",apps/web/src/contextMenuFallback.ts lines 206 to 212OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -137,6 +198,15 @@137198 svg.setAttribute(138199 "class",139200 tone === "destructive"140- ? "size-4.5 shrink-0 sm:size-4"141- : "size-4.5 shrink-0 text-muted-foreground sm:size-4",201+ ? "size-4.5 shrink-0 text-destructive-foreground sm:size-4"202+ : tone === "warning"203+ ? "size-4.5 shrink-0 text-warning-foreground sm:size-4"204+ : "size-4.5 shrink-0 text-muted-foreground sm:size-4",142205 );206+ svg.style.cssText =207+ "width:1rem;height:1rem;flex-shrink:0;pointer-events:none;" +208+ (tone === "destructive"209+ ? "color:var(--destructive-foreground);"210+ : tone === "warning"211+ ? "color:var(--warning-foreground);"212+ : "color:var(--contrast-muted-foreground);opacity:0.8;");
- @@ -12,3 +14,7 @@1214 * share the same atom registry as routed UI.1315 */1416 export function AppRoot({ router }: { readonly router: AppRouter }) {17+ useEffect(() => {18+ if (typeof window !== "undefined" && window.desktopBridge) {19+ return;20+ }apps/web/src/contextMenuFallback.ts line 818Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -473,0 +801,21 @@801+ document.execCommand("copy");802+ }803+ } else {804+ restoreWindowSelection();805+ const text = selectedText;806+ if (text) {807+ try {808+ await navigator.clipboard.writeText(text);809+ } catch {810+ document.execCommand("copy");811+ }812+ }813+ }814+ } else if (clicked === "paste") {815+ try {816+ const text = await navigator.clipboard.readText();817+ if (isInputElement || isTextAreaElement) {818+ const input = target as HTMLInputElement | HTMLTextAreaElement;819+ try {820+ const start = inputSelection?.start ?? input.selectionStart ?? input.value.length;821+ const end = inputSelection?.end ?? input.selectionEnd ?? input.value.length;
- apps/desktop/src/window/DesktopWindow.ts line 532Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -515,9 +517,4 @@515517 menuTemplate.push({ type: "separator" });516518 }517519518- menuTemplate.push(519- { role: "cut", enabled: params.editFlags.canCut },520- { role: "copy", enabled: params.editFlags.canCopy },521- { role: "paste", enabled: params.editFlags.canPaste },522- { role: "selectAll", enabled: params.editFlags.canSelectAll },523- );520+ if (menuTemplate.length > 0) {apps/web/src/contextMenuFallback.ts line 832OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -473,0 +812,21 @@812+ }813+ }814+ } else if (clicked === "paste") {815+ try {816+ const text = await navigator.clipboard.readText();817+ if (isInputElement || isTextAreaElement) {818+ const input = target as HTMLInputElement | HTMLTextAreaElement;819+ try {820+ const start = inputSelection?.start ?? input.selectionStart ?? input.value.length;821+ const end = inputSelection?.end ?? input.selectionEnd ?? input.value.length;822+ input.setRangeText(text, start, end, "end");823+ } catch {824+ // Fallback for inputs that don't support setRangeText.825+ input.value += text;826+ }827+ input.dispatchEvent(new Event("input", { bubbles: true }));828+ } else {829+ document.execCommand("insertText", false, text);830+ }831+ } catch {832+ document.execCommand("paste");
- apps/desktop/src/window/DesktopWindow.ts line 544Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -522,4 +520,18 @@522- { role: "selectAll", enabled: params.editFlags.canSelectAll },523- );520+ if (menuTemplate.length > 0) {521+ // Strip trailing separator before showing.522+ const last = menuTemplate[menuTemplate.length - 1];523+ if (last?.type === "separator") {524+ menuTemplate.pop();525+ }526+ void runPromise(electronMenu.popupTemplate({ window, template: menuTemplate }));527+ // Electron-exclusive entries own this gesture.528+ event.preventDefault();529+ return;530+ }524531525- void runPromise(electronMenu.popupTemplate({ window, template: menuTemplate }));532+ // Preserve the native editing menu for text selections and editable533+ // controls, while keeping empty-space right-clicks dismissed.534+ if (params.isEditable || params.selectionText.length > 0) {535+ return;536+ }537+ event.preventDefault();
- @@ -473,0 +755,21 @@755+756+ if (!clicked) {757+ return;758+ }759+760+ if (clicked === "cut") {761+ if (isInputElement || isTextAreaElement) {762+ const input = target as HTMLInputElement | HTMLTextAreaElement;763+ try {764+ const start = inputSelection?.start ?? input.selectionStart ?? 0;765+ const end = inputSelection?.end ?? input.selectionEnd ?? 0;766+ const text = input.value.slice(start, end);767+ if (text) {768+ try {769+ await navigator.clipboard.writeText(text);770+ } catch {771+ document.execCommand("copy");772+ }773+ input.setRangeText("", start, end, "end");774+ input.dispatchEvent(new Event("input", { bubbles: true }));775+ }
- @@ -2854,12 +2854,13 @@28542854 const clicked = await settlePromise(() =>28552855 api.contextMenu.show(28562856 [2857- { id: "settle", label: `Settle (${count})` },2857+ { id: "settle", label: `Settle (${count})`, icon: "circle-check" },28582858 ...(canSnoozeSelection28592859 ? [28602860 {28612861 id: "snooze",28622862 label: `Snooze (${count})`,2863+ icon: "clock",28632864 children: snoozePresets.map((preset) => ({28642865 id: `snooze:${preset.id}`,28652866 label: `${preset.label} (${preset.whenLabel})`,
- @@ -182,3 +248,13 @@182248 return false;183249 }184250251+function findContentEditableHost(element: HTMLElement): HTMLElement | null {252+ for (let current: HTMLElement | null = element; current; current = current.parentElement) {253+ const contentEditable = current.getAttribute("contenteditable");254+ if (contentEditable !== null) {255+ return contentEditable.toLowerCase() === "false" || !current.isContentEditable256+ ? null257+ : current;258+ }259+ }260+ return null;
- @@ -2854,12 +2854,13 @@28542854 const clicked = await settlePromise(() =>28552855 api.contextMenu.show(28562856 [2857- { id: "settle", label: `Settle (${count})` },2857+ { id: "settle", label: `Settle (${count})`, icon: "circle-check" },28582858 ...(canSnoozeSelection28592859 ? [28602860 {28612861 id: "snooze",28622862 label: `Snooze (${count})`,2863+ icon: "clock",28632864 children: snoozePresets.map((preset) => ({28642865 id: `snooze:${preset.id}`,28652866 label: `${preset.label} (${preset.whenLabel})`,
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
e3644d3a-b42d-46f3-a134-67014a0d4b7bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.