Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions frontend/app/view/term/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -269,6 +269,11 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
}, [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);
Expand Down Expand Up @@ -376,12 +381,20 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>

const handleContextMenu = React.useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
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 (
Expand Down
29 changes: 29 additions & 0 deletions frontend/app/view/term/termutil-rightclick.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
18 changes: 18 additions & 0 deletions frontend/app/view/term/termutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
2 changes: 2 additions & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 8 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@
"term:trimtrailingwhitespace": {
"type": "boolean"
},
"term:rightclickmenu": {
"type": "string",
"enum": [
"auto",
"wave",
"app"
]
},
"editor:minimapenabled": {
"type": "boolean"
},
Expand Down