From 0f184c28b056b977593fa7f850217063d3043642 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Fri, 17 Apr 2026 19:07:04 -0400 Subject: [PATCH] fix(web): use capture-phase keydown listener so CTRL+J toggles terminal from terminal focus on Windows (#2113) (#2142) Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- apps/web/src/components/ChatView.tsx | 4 ++-- apps/web/src/keybindings.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 06d8e8db5d8918313268d68a16894bea07b54c39..47dad09ea29c07e35c169c34d06a91aa3af5d654 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2290,8 +2290,8 @@ export default function ChatView(props: ChatViewProps) { event.stopPropagation(); void runProjectScript(script); }; - window.addEventListener("keydown", handler); - return () => window.removeEventListener("keydown", handler); + window.addEventListener("keydown", handler, true); + return () => window.removeEventListener("keydown", handler, true); }, [ activeProject, terminalState.terminalOpen, diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index 2c968e6bc326e9272e9334ecd9ab746e02d2b194..683afbbfe44f03a2e6b65fff1f248f0ac67cedac 100644 --- a/apps/web/src/keybindings.test.ts +++ b/apps/web/src/keybindings.test.ts @@ -131,6 +131,15 @@ describe("isTerminalToggleShortcut", () => { isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, { platform: "Win32" }), ); }); + + it("matches Ctrl+J on non-macOS while terminalFocus is true", () => { + assert.isTrue( + isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, { + platform: "Win32", + context: { terminalFocus: true }, + }), + ); + }); }); describe("split/new/close terminal shortcuts", () => { -- 2.54.0