From 90a9b6169143deba501cf2ff94e063105e4623c5 Mon Sep 17 00:00:00 2001 From: Archie Cho Date: Tue, 24 Nov 2026 15:48:54 +0900 Subject: [PATCH] feat(term): add a setting to yield right-click to the terminal app Applications that enable mouse tracking (herdr, tmux, btop, ...) draw their own context menu on right-click, but Wave's menu opened on top of it, so the app's menu was unreachable. Add `term:rightclickmenu` (auto | wave | app, default auto). In auto mode the right-click is left to the app while the terminal reports a mouse tracking mode other than none; otherwise Wave keeps its menu. The event is always prevented and stopped, so Chromium's text menu still cannot appear over the terminal. Unit tests cover the auto/wave/app resolution in termutil.test. --- frontend/app/view/term/term.tsx | 17 +++++++++-- .../app/view/term/termutil-rightclick.test.ts | 29 +++++++++++++++++++ frontend/app/view/term/termutil.ts | 18 ++++++++++++ frontend/types/gotypes.d.ts | 2 ++ pkg/wconfig/metaconsts.go | 1 + pkg/wconfig/settingsconfig.go | 1 + schema/settings.json | 8 +++++ 7 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 frontend/app/view/term/termutil-rightclick.test.ts diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 67eb5737c6..960fced9aa 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -24,7 +24,7 @@ import * as React from "react"; import { TermLinkTooltip } from "./term-tooltip"; import { TermStickers } from "./termsticker"; import { TermThemeUpdater } from "./termtheme"; -import { computeTheme, normalizeCursorStyle } from "./termutil"; +import { computeTheme, normalizeCursorStyle, shouldShowWaveContextMenu } from "./termutil"; import { TermWrap } from "./termwrap"; import "./xterm.css"; @@ -269,6 +269,11 @@ const TerminalView = ({ blockId, model }: ViewComponentProps) => }, [searchOpts]); // end search + const termRightClickMenu = + (blockData?.meta?.["term:rightclickmenu"] as string) ?? + (termSettings?.["term:rightclickmenu"] as string) ?? + "auto"; + React.useEffect(() => { const fullConfig = globalStore.get(atoms.fullConfigAtom); const termThemeName = globalStore.get(model.termThemeNameAtom); @@ -376,12 +381,20 @@ const TerminalView = ({ blockId, model }: ViewComponentProps) => const handleContextMenu = React.useCallback( (e: React.MouseEvent) => { + const mouseTrackingMode = model.termRef.current?.terminal.modes.mouseTrackingMode; + // Always stop the event: otherwise Chromium's text menu or the app-level + // Paste menu shows on top of the terminal app's own right-click menu. e.preventDefault(); e.stopPropagation(); + if (!shouldShowWaveContextMenu(termRightClickMenu, mouseTrackingMode)) { + // The terminal app (herdr, tmux, btop, ...) is using the mouse and already + // received the click; just don't cover it with Wave's menu. + return; + } const menuItems = model.getContextMenuItems(); ContextMenuModel.getInstance().showContextMenu(menuItems, e); }, - [model] + [model, termRightClickMenu] ); return ( diff --git a/frontend/app/view/term/termutil-rightclick.test.ts b/frontend/app/view/term/termutil-rightclick.test.ts new file mode 100644 index 0000000000..0775085756 --- /dev/null +++ b/frontend/app/view/term/termutil-rightclick.test.ts @@ -0,0 +1,29 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; +import { shouldShowWaveContextMenu } from "./termutil"; + +describe("shouldShowWaveContextMenu", () => { + it("yields the right-click to an app that is tracking the mouse in auto mode", () => { + expect(shouldShowWaveContextMenu("auto", "vt200")).toBe(false); + expect(shouldShowWaveContextMenu("auto", "drag")).toBe(false); + expect(shouldShowWaveContextMenu("auto", "any")).toBe(false); + }); + + it("shows the Wave menu when no app is tracking the mouse in auto mode", () => { + expect(shouldShowWaveContextMenu("auto", "none")).toBe(true); + expect(shouldShowWaveContextMenu(undefined, undefined)).toBe(true); + expect(shouldShowWaveContextMenu(null, null)).toBe(true); + }); + + it("honors the explicit settings", () => { + expect(shouldShowWaveContextMenu("wave", "drag")).toBe(true); + expect(shouldShowWaveContextMenu("app", "none")).toBe(false); + }); + + it("treats unknown settings as auto", () => { + expect(shouldShowWaveContextMenu("bogus", "drag")).toBe(false); + expect(shouldShowWaveContextMenu("bogus", "none")).toBe(true); + }); +}); diff --git a/frontend/app/view/term/termutil.ts b/frontend/app/view/term/termutil.ts index add5e86e05..007c8b157c 100644 --- a/frontend/app/view/term/termutil.ts +++ b/frontend/app/view/term/termutil.ts @@ -408,3 +408,21 @@ export function isLikelyOnSameHost(lastCommand: string): boolean { export function quoteForPosixShell(filePath: string): string { return "'" + filePath.replace(/'/g, "'\\''") + "'"; } + +export type TermRightClickMenuMode = "auto" | "wave" | "app"; + +// "auto" yields the right-click to the terminal app while it is using the mouse +// (e.g. herdr, tmux, btop) and otherwise keeps Wave's own menu. +export function shouldShowWaveContextMenu( + setting: string | null | undefined, + mouseTrackingMode: string | null | undefined +): boolean { + const mode: TermRightClickMenuMode = setting === "wave" || setting === "app" ? setting : "auto"; + if (mode === "wave") { + return true; + } + if (mode === "app") { + return false; + } + return (mouseTrackingMode ?? "none") === "none"; +} diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index c5b870d7ed..a2616ae621 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -1426,6 +1426,7 @@ declare global { "term:durable"?: boolean; "term:showsplitbuttons"?: boolean; "term:trimtrailingwhitespace"?: boolean; + "term:rightclickmenu"?: string; "editor:minimapenabled"?: boolean; "editor:stickyscrollenabled"?: boolean; "editor:wordwrap"?: boolean; @@ -1589,6 +1590,7 @@ declare global { "debug:panictype"?: string; "block:view"?: string; "block:controller"?: string; + "block:subblock"?: boolean; "ai:backendtype"?: string; "ai:local"?: boolean; "wsh:cmd"?: string; diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 7d5bba5d9d..203e756811 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -61,6 +61,7 @@ const ( ConfigKey_TermDurable = "term:durable" ConfigKey_TermShowSplitButtons = "term:showsplitbuttons" ConfigKey_TermTrimTrailingWhitespace = "term:trimtrailingwhitespace" + ConfigKey_TermRightClickMenu = "term:rightclickmenu" ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index 67118b1670..2f5d50c76e 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -112,6 +112,7 @@ type SettingsType struct { TermDurable *bool `json:"term:durable,omitempty"` TermShowSplitButtons bool `json:"term:showsplitbuttons,omitempty"` TermTrimTrailingWhitespace *bool `json:"term:trimtrailingwhitespace,omitempty"` + TermRightClickMenu string `json:"term:rightclickmenu,omitempty" jsonschema:"enum=auto,enum=wave,enum=app"` EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` diff --git a/schema/settings.json b/schema/settings.json index f341a0f365..73970cb012 100644 --- a/schema/settings.json +++ b/schema/settings.json @@ -174,6 +174,14 @@ "term:trimtrailingwhitespace": { "type": "boolean" }, + "term:rightclickmenu": { + "type": "string", + "enum": [ + "auto", + "wave", + "app" + ] + }, "editor:minimapenabled": { "type": "boolean" },