Skip to content

fix(terminal): protect held Ctrl/Cmd+W close shortcut - #5322

Merged
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
StiensWout:t3code/protect-held-terminal-close-shortcut
Aug 4, 2026
Merged

fix(terminal): protect held Ctrl/Cmd+W close shortcut#5322
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
StiensWout:t3code/protect-held-terminal-close-shortcut

Conversation

@StiensWout

@StiensWout StiensWout commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prevent the terminal key handler from allowing the close shortcut to reach the browser default
  • block repeated close-shortcut keydowns at the web window level after the last terminal unmounts
  • reject repeated CmdOrCtrl+W input before Electron's native window-menu accelerator
  • add focused web and desktop regressions

Root 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.ts
  • pnpm exec vp test run src/window/DesktopWindow.test.ts
  • pnpm exec tsgo --noEmit in apps/web
  • pnpm exec tsgo --noEmit in apps/desktop
  • formatter check for all touched files

Visual demo

Held terminal close protection

Note

Block held Ctrl/Cmd+W from repeatedly closing terminal windows

  • Adds preventTerminalCloseShortcut and preventRepeatedTerminalCloseShortcut utility functions in terminalCloseShortcut.ts to intercept close shortcut key events.
  • Adds a before-input-event listener in DesktopWindow.ts that blocks auto-repeated Cmd+W (macOS) or Ctrl+W (other platforms) from reaching the native window menu.
  • Updates ThreadTerminalDrawer.tsx and ChatView.tsx to 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 / preventRepeatedTerminalCloseShortcut in terminalCloseShortcut.ts. The terminal drawer calls the deliberate-close guard in its before-key path; ChatView stops repeated close shortcuts at the window level when no terminal is focused.

Desktop: Registers a before-input-event listener that preventDefaults only auto-repeated Cmd+W (macOS) or Ctrl+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.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a144b090-a46f-4a34-8d15-210fecca610b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Aug 4, 2026
@StiensWout
StiensWout marked this pull request as ready for review August 4, 2026 07:46
@macroscopeapp

macroscopeapp Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

@juliusmarminge
juliusmarminge merged commit 5538672 into pingdotgg:main Aug 4, 2026
22 checks passed
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Aug 4, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Holding Ctrl+W to delete text on the t3code terminal eventually closes the terminal and the t3code app

2 participants