fix(terminal): protect held Ctrl/Cmd+W close shortcut - #5322
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 3334961 This is a focused bug fix preventing held Cmd/Ctrl+W from accidentally closing the browser window after a terminal closes. The implementation is straightforward keyboard event handling with comprehensive tests and no side effects beyond the intended fix. You can customize Macroscope's approvability policy. Learn more. |
## What's Changed * fix(web): blink the terminal cursor again by @StiensWout in pingdotgg/t3code#5314 * fix(terminal): protect held Ctrl/Cmd+W close shortcut by @StiensWout in pingdotgg/t3code#5322 * fix(server): strip replayable terminal queries from history by @StiensWout in pingdotgg/t3code#5319 * fix(contracts): decode ServerProviders forward-compatibly by @Brechard in pingdotgg/t3code#5327 * fix(web): simplify chat code blocks by @t3-code[bot] in pingdotgg/t3code#5301 * fix(web): align multiline error alert controls by @t3-code[bot] in pingdotgg/t3code#5304 * Upgrade Effect to beta.103 by @juliusmarminge in pingdotgg/t3code#5331 ## New Contributors * @Brechard made their first contribution in pingdotgg/t3code#5327 **Full Changelog**: pingdotgg/t3code@v0.0.32-nightly.20260804.993...v0.0.32-nightly.20260804.997 Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.32-nightly.20260804.997
Summary
CmdOrCtrl+Winput before Electron's native window-menu acceleratorRoot cause
Closing the last terminal unmounts the focused terminal before a held shortcut finishes auto-repeating. Those later repeats no longer resolve the terminal command and could fall through to browser tab-close or Electron window-close behavior.
Validation
pnpm exec vp test run --project unit src/lib/terminalCloseShortcut.test.ts src/components/ThreadTerminalDrawer.test.ts src/keybindings.test.tspnpm exec vp test run src/window/DesktopWindow.test.tspnpm exec tsgo --noEmitinapps/webpnpm exec tsgo --noEmitinapps/desktopVisual demo
Note
Block held Ctrl/Cmd+W from repeatedly closing terminal windows
preventTerminalCloseShortcutandpreventRepeatedTerminalCloseShortcututility functions interminalCloseShortcut.tsto intercept close shortcut key events.before-input-eventlistener inDesktopWindow.tsthat blocks auto-repeated Cmd+W (macOS) or Ctrl+W (other platforms) from reaching the native window menu.ThreadTerminalDrawer.tsxandChatView.tsxto call these guards, stopping repeated close shortcuts from propagating while leaving deliberate single presses unaffected.Macroscope summarized 3334961.
closes #2787
Note
Low Risk
Keyboard-input handling only; no auth or data paths. Slight risk of over-blocking if repeat detection diverges from platform behavior, but deliberate closes are explicitly left alone.
Overview
Fixes a bug where holding the terminal close shortcut (
Ctrl/Cmd+W) could close the browser tab or Electron window after the last terminal unmounts, because auto-repeat key events no longer hit terminal handlers.Web: Adds
preventTerminalCloseShortcut/preventRepeatedTerminalCloseShortcutinterminalCloseShortcut.ts. The terminal drawer calls the deliberate-close guard in its before-key path;ChatViewstops repeated close shortcuts at the window level when no terminal is focused.Desktop: Registers a
before-input-eventlistener thatpreventDefaults only auto-repeatedCmd+W(macOS) orCtrl+W(other platforms), so repeats never reach Electron’s native window-menu close accelerator. Single presses are unchanged.Regression tests cover the new helpers and the desktop listener.
Reviewed by Cursor Bugbot for commit 3334961. Bugbot is set up for automated code reviews on this repo. Configure here.