From a85d801088dca272ea2905c13135ed2f30bbe5d9 Mon Sep 17 00:00:00 2001 From: zerafachris Date: Thu, 16 Jul 2026 10:26:46 +0200 Subject: [PATCH] fix(windows): address clipboard copy failure in TUI Fixes #8977 --- src/main/window/clipboard-ipc-handlers.ts | 13 ++++++++++++- .../terminal-pane/use-terminal-pane-lifecycle.ts | 11 ++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/window/clipboard-ipc-handlers.ts b/src/main/window/clipboard-ipc-handlers.ts index f6c98d6bb2d..8d727bff6b0 100644 --- a/src/main/window/clipboard-ipc-handlers.ts +++ b/src/main/window/clipboard-ipc-handlers.ts @@ -142,7 +142,18 @@ export function registerClipboardHandlers(store: Store): void { ) ipcMain.handle('clipboard:writeText', async (event, text: string) => { assertTrustedClipboardSender(event) - return clipboard.writeText(await assertClipboardTextWriteWithinLimitWithYield(text)) + const newText = await assertClipboardTextWriteWithinLimitWithYield(text) + if (process.platform === 'win32') { + try { + // Use a PowerShell fallback for Windows to improve reliability + await runCommand('powershell', ['-Command', `Set-Clipboard -Value $input`], newText) + } catch (error) { + console.error('PowerShell clipboard write failed, falling back to Electron API', error) + clipboard.writeText(newText) + } + } else { + clipboard.writeText(newText) + } }) ipcMain.handle('clipboard:writeSelectionText', async (event, text: string) => { assertTrustedClipboardSender(event) diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts index e1fe139d445..3512de6c6aa 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts @@ -1130,9 +1130,14 @@ export function useTerminalPaneLifecycle({ if (!selection) { return } - void window.api.ui.writeClipboardText(selection).catch(() => { - /* ignore clipboard write failures */ - }) + void window.api.ui + .writeClipboardText(selection) + .then(() => { + // TODO(orca): Show a "Copied" toast notification + }) + .catch(() => { + // TODO(orca): Show a "Copy failed" toast notification + }) }) selectionDisposablesRef.current.set(pane.id, selectionDisposable) // Hide mouse cursor while typing — classic terminal UX, scoped to the