feat(terminal): add an optional Paste on right click (#6825)

Settings › Tools › Terminal gains Paste on right click (terminal.rightClickPaste, off by default). When on, a plain right-click in a terminal pane pastes the clipboard through the same path as Paste and middle-click paste, so bracketed paste and multiline handling are unchanged; Ctrl or Shift + right-click still opens the context menu, and focus stays in the pane.

Fixes #6634
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-29 16:55:39 +08:00
1 джерело 4812d28614
коміт db266643aa
11 files changed
+60

No files matched your search

+3
Переглянути файл
@@ -617,6 +617,8 @@ pub struct TerminalSettings {
pub mouse_reporting: bool,
pub copy_on_selection: bool,
pub paste_on_middle_click: bool,
/// Right-click pastes instead of opening the context menu (Ctrl or Shift + right-click still opens it).
pub right_click_paste: bool,
pub override_ide_shortcuts: bool,
pub shell_integration: bool,
pub highlight_hyperlinks: bool,
@@ -655,6 +657,7 @@ impl Default for TerminalSettings {
mouse_reporting: true,
copy_on_selection: false,
paste_on_middle_click: true,
right_click_paste: false,
override_ide_shortcuts: true,
shell_integration: true,
highlight_hyperlinks: true,
+1
Переглянути файл
@@ -90,6 +90,7 @@ With **Shell integration** on, zsh, bash and fish report the current directory a
| **Mouse reporting** | on | Off: programs can't capture the mouse. |
| **Copy to clipboard on selection** | off | |
| **Paste on middle mouse button click** | on | |
| **Paste on right click** | off | On: right-click pastes; Ctrl or Shift + right-click opens the context menu. |
| **Move focus to the Editor with Escape** | off | Otherwise `Esc` goes to the shell. |
| **Override IDE shortcuts** | on | See above. |
| **Shell integration** | on | |
+1
Переглянути файл
@@ -90,6 +90,7 @@ OpenIDEA 会按项目记住终端标签页:各自的目录、自定义名称
| **鼠标报告** | 开 | 关闭后程序无法捕获鼠标。 |
| **选择时复制到剪贴板** | 关 | |
| **点击鼠标中键时粘贴** | 开 | |
| **右键单击时粘贴** | 关 | 开启后右键单击直接粘贴;按住 Ctrl 或 Shift 右键单击仍打开上下文菜单。 |
| **按 Escape 将焦点移到编辑器** | 关 | 关闭时 `Esc` 发给 Shell。 |
| **覆盖 IDE 快捷键** | 开 | 见上文。 |
| **Shell 集成** | 开 | |
+35
Переглянути файл
@@ -118,6 +118,41 @@ for (const { width, split } of [{ width: 220 }, { width: 280 }, { width: 520 },
});
}
test("Paste on right click pastes on a plain right-click and keeps the menu on Shift+right-click", async ({
workbench: page,
}) => {
const terminal = page.getByRole("region", { name: "Terminal", exact: true });
await page.evaluate(async () => {
const layout = await import("/src/workbench/toolwindows/store.ts" as string);
layout.showToolWindow("terminal", true);
});
const output = terminal.getByRole("tabpanel").locator(".xterm");
await expect(terminal.locator(".xterm-helper-textarea")).toBeFocused();
await page.evaluate(async () => {
const { useProject } = await import("/src/platform/project.ts" as string);
const settings = useProject.getState().settings ?? {};
useProject.setState({
settings: { ...settings, terminal: { ...settings.terminal, rightClickPaste: true } },
});
const { activeSession } = await import("/src/features/terminal/store.ts" as string);
const session = activeSession();
const w = window as unknown as { __pastes: number };
w.__pastes = 0;
session.pasteClipboard = () => {
w.__pastes += 1;
return Promise.resolve();
};
});
const menu = page.getByRole("menu", { name: "Context menu" });
await output.click({ button: "right", position: { x: 25, y: 50 } });
await expect.poll(() => page.evaluate(() => (window as unknown as { __pastes: number }).__pastes)).toBe(1);
await expect(menu).toBeHidden();
await expect(terminal.locator(".xterm-helper-textarea")).toBeFocused();
await output.click({ button: "right", modifiers: ["Shift"], position: { x: 25, y: 50 } });
await expect(menu.getByRole("menuitem", { name: /^Paste/ })).toBeVisible();
expect(await page.evaluate(() => (window as unknown as { __pastes: number }).__pastes)).toBe(1);
});
test("wide terminal search leaves the grid in place and avoids covering the active match", async ({
workbench: page,
}) => {
+2
Переглянути файл
@@ -15104,6 +15104,8 @@ export type TerminalSettings = {
mouseReporting?: boolean,
copyOnSelection?: boolean,
pasteOnMiddleClick?: boolean,
/** Right-click pastes instead of opening the context menu (Ctrl or Shift + right-click still opens it). */
rightClickPaste?: boolean,
overrideIdeShortcuts?: boolean,
shellIntegration?: boolean,
highlightHyperlinks?: boolean,
+1
Переглянути файл
@@ -254,6 +254,7 @@ function TerminalOptions() {
<BoundToggle k="terminal.mouseReporting" label="Mouse reporting" />
<BoundToggle k="terminal.copyOnSelection" label="Copy to clipboard on selection" />
<BoundToggle k="terminal.pasteOnMiddleClick" label="Paste on middle mouse button click" />
<BoundToggle k="terminal.rightClickPaste" label="Paste on right click" />
<BoundToggle
k="terminal.escapeToEditor"
label="Move focus to the Editor with Escape"
+10
Переглянути файл
@@ -7,6 +7,7 @@ import { ToolWindowHeader, useOwnToolWindowHeader } from "@/workbench/toolwindow
import { usePlatform } from "@/platform/platformInfo";
import { commands, isTauri } from "@/platform/ipc";
import { useTx } from "@/platform/i18n";
import { workflowSettings } from "@/platform/workflowSettings";
import {
Badge,
dropZoneAt,
@@ -102,6 +103,10 @@ function paneMenu(e: MouseEvent, key: string) {
// Right-clicking focuses the terminal, like IDEA; otherwise the menu closing
// restores focus to whatever was focused before it, often the editor.
session.focus();
if (rightClickPastes(e, workflowSettings().terminal.rightClickPaste)) {
void session.pasteClipboard();
return;
}
const exited = session.state.status === "exited" || session.state.status === "error";
const mac = usePlatform.getState().os === "macos";
const items: MenuItem[] = [
@@ -141,6 +146,11 @@ function paneMenu(e: MouseEvent, key: string) {
showContextMenu(e, items);
}
/** With Paste on right click on, a plain right-click pastes; Ctrl or Shift + right-click still opens the menu. */
export function rightClickPastes(e: { ctrlKey: boolean; shiftKey: boolean }, enabled: boolean): boolean {
return enabled && !e.ctrlKey && !e.shiftKey;
}
/** The groups of a split window whose headers show its title and its buttons. */
interface Corners {
title: string;
+1
Переглянути файл
@@ -64,6 +64,7 @@ export const CLIENT_SETTINGS_KEYS = [
"terminal.mouseReporting",
"terminal.copyOnSelection",
"terminal.pasteOnMiddleClick",
"terminal.rightClickPaste",
"terminal.overrideIdeShortcuts",
"terminal.highlightHyperlinks",
"terminal.runCommandsUsingIde",
+1
Переглянути файл
@@ -2220,6 +2220,7 @@
"Password:": "密碼:",
"Password already stored": "已儲存密碼",
"Paste": "貼上",
"Paste on right click": "按右鍵時貼上",
"Paste on middle mouse button click": "點選滑鼠中鍵時貼上",
"Patch copied to the clipboard": "補丁已複製到剪貼簿",
"Patch destination": "補丁目標",
+1
Переглянути файл
@@ -2794,6 +2794,7 @@
"Password:": "密码:",
"Password already stored": "已存储密码",
"Paste": "粘贴",
"Paste on right click": "右键单击时粘贴",
"Paste on middle mouse button click": "点击鼠标中键时粘贴",
"Patch copied to the clipboard": "补丁已复制到剪贴板",
"Patch destination": "补丁目标",
+4
Переглянути файл
@@ -205,6 +205,8 @@ export interface TerminalSettingsValid {
mouseReporting: boolean;
copyOnSelection: boolean;
pasteOnMiddleClick: boolean;
/** Right-click pastes instead of opening the context menu (Ctrl or Shift + right-click still opens it). */
rightClickPaste: boolean;
overrideIdeShortcuts: boolean;
shellIntegration: boolean;
highlightHyperlinks: boolean;
@@ -441,6 +443,7 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
mouseReporting: true,
copyOnSelection: false,
pasteOnMiddleClick: true,
rightClickPaste: false,
overrideIdeShortcuts: true,
shellIntegration: true,
highlightHyperlinks: true,
@@ -686,6 +689,7 @@ export function validateTerminal(raw: unknown): TerminalSettingsValid {
mouseReporting: bool(v.mouseReporting, d.mouseReporting),
copyOnSelection: bool(v.copyOnSelection, d.copyOnSelection),
pasteOnMiddleClick: bool(v.pasteOnMiddleClick, d.pasteOnMiddleClick),
rightClickPaste: bool(v.rightClickPaste, d.rightClickPaste),
overrideIdeShortcuts: bool(v.overrideIdeShortcuts, d.overrideIdeShortcuts),
shellIntegration: bool(v.shellIntegration, d.shellIntegration),
highlightHyperlinks: bool(v.highlightHyperlinks, d.highlightHyperlinks),