From 374e56e553daccf730c2c8dcb0b6e161980b43c1 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 17 Aug 2026 11:40:05 +0200 Subject: [PATCH] fix(tui): avoid duplicate VS Code right-click paste closes #8186 --- packages/coding-agent/CHANGELOG.md | 1 + packages/tui/CHANGELOG.md | 4 ++++ packages/tui/src/tui-alt-screen.ts | 8 +++++++- packages/tui/test/tui-alt-screen.test.ts | 11 ++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 5f433be9a..d8866f539 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -7,6 +7,7 @@ - Fixed `pi.registerFlag()` accepting default values that do not match the declared flag type ([#8064](https://github.com/earendil-works/pi/issues/8064)). - Fixed Z.AI Coding Plan defaults referencing the removed GLM-5.1 model ([#8096](https://github.com/earendil-works/pi/issues/8096)). - Fixed repeated ambiguous truncated-response recovery being mislabeled as context overflow ([#8130](https://github.com/earendil-works/pi/issues/8130)). +- Fixed duplicate fullscreen right-click paste in VS Code-based terminals on Windows ([#8186](https://github.com/earendil-works/pi/issues/8186)). ## [0.84.2] - 2026-08-14 diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index ae7c20028..6c0416351 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fixed duplicate fullscreen right-click paste in VS Code-based terminals on Windows ([#8186](https://github.com/earendil-works/pi/issues/8186)). + ## [0.84.2] - 2026-08-14 ### Added diff --git a/packages/tui/src/tui-alt-screen.ts b/packages/tui/src/tui-alt-screen.ts index 783a92ab8..855fa0f71 100644 --- a/packages/tui/src/tui-alt-screen.ts +++ b/packages/tui/src/tui-alt-screen.ts @@ -695,7 +695,13 @@ export class TuiAltScreen extends TuiBase implements ViewportTUI { } private handleRightClickPaste(event: SgrMouseEvent): boolean { - if (!this.onRightClickPaste || process.platform !== "win32" || event.release || event.button !== 2) { + if ( + !this.onRightClickPaste || + process.platform !== "win32" || + process.env.TERM_PROGRAM?.toLowerCase() === "vscode" || + event.release || + event.button !== 2 + ) { return false; } try { diff --git a/packages/tui/test/tui-alt-screen.test.ts b/packages/tui/test/tui-alt-screen.test.ts index 2166debe7..a681cfd8c 100644 --- a/packages/tui/test/tui-alt-screen.test.ts +++ b/packages/tui/test/tui-alt-screen.test.ts @@ -225,8 +225,9 @@ describe("TuiAltScreen", () => { } }); - it("invokes the right-click paste handler only on Windows", () => { + it("invokes the right-click paste handler only on Windows outside VS Code", () => { const platformDescriptor = Object.getOwnPropertyDescriptor(process, "platform"); + const termProgram = process.env.TERM_PROGRAM; assert.ok(platformDescriptor); const terminal = new VirtualTerminal(); let pasteCount = 0; @@ -237,17 +238,25 @@ describe("TuiAltScreen", () => { }); try { Object.defineProperty(process, "platform", { configurable: true, value: "win32" }); + delete process.env.TERM_PROGRAM; tui.start(); terminal.sendInput("\x1b[<2;1;1M"); terminal.sendInput("\x1b[<2;1;1m"); assert.strictEqual(pasteCount, 1); + process.env.TERM_PROGRAM = "vscode"; + terminal.sendInput("\x1b[<2;1;1M"); + assert.strictEqual(pasteCount, 1); + Object.defineProperty(process, "platform", { configurable: true, value: "linux" }); + delete process.env.TERM_PROGRAM; terminal.sendInput("\x1b[<2;1;1M"); assert.strictEqual(pasteCount, 1); } finally { tui.stop(); Object.defineProperty(process, "platform", platformDescriptor); + if (termProgram === undefined) delete process.env.TERM_PROGRAM; + else process.env.TERM_PROGRAM = termProgram; } });