Skip to content

Commit d4bd892

Browse files
feat(web): mod+w closes the active right panel tab before the window (#9363)
Co-authored-by: Claude Code <[email protected]>
1 parent b5f4e81 commit d4bd892

7 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎apps/server/src/keybindings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
207207
assert.equal(defaultsByCommand.get("sidebar.toggle"), "mod+b");
208208
assert.equal(defaultsByCommand.get("rightPanel.toggle"), "mod+alt+b");
209209
assert.isFalse(defaultsByCommand.has("rightPanel.toggleMaximized"));
210+
assert.equal(defaultsByCommand.get("rightPanel.close"), "mod+w");
210211
assert.equal(defaultsByCommand.get("terminal.splitVertical"), "mod+shift+d");
211212
assert.equal(defaultsByCommand.get("modelPicker.jump.1"), "mod+1");
212213
assert.equal(defaultsByCommand.get("modelPicker.jump.9"), "mod+9");

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5691,6 +5691,16 @@ function ChatViewContent(props: ChatViewProps) {
56915691
return;
56925692
}
56935693

5694+
if (command === "rightPanel.close") {
5695+
// Nothing open: leave the event alone so the shortcut keeps its
5696+
// native meaning (close window on desktop, close tab in a browser).
5697+
if (!activeRightPanelSurface) return;
5698+
event.preventDefault();
5699+
event.stopPropagation();
5700+
if (!event.repeat) closeRightPanelSurface(activeRightPanelSurface);
5701+
return;
5702+
}
5703+
56945704
if (command === "terminal.split") {
56955705
event.preventDefault();
56965706
event.stopPropagation();
@@ -5779,6 +5789,7 @@ function ChatViewContent(props: ChatViewProps) {
57795789
terminalUiState.terminalOpen,
57805790
terminalUiState.activeTerminalId,
57815791
activeThreadId,
5792+
closeRightPanelSurface,
57825793
requestCloseTerminal,
57835794
requestClosePanelTerminal,
57845795
createNewTerminal,

‎apps/web/src/keybindings.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ const DEFAULT_BINDINGS = compile([
108108
command: "terminal.close",
109109
whenAst: whenIdentifier("terminalFocus"),
110110
},
111+
{
112+
shortcut: modShortcut("w"),
113+
command: "rightPanel.close",
114+
whenAst: whenNot(whenIdentifier("terminalFocus")),
115+
},
111116
{
112117
shortcut: modShortcut("d"),
113118
command: "diff.toggle",
@@ -751,6 +756,24 @@ describe("resolveShortcutCommand", () => {
751756
);
752757
});
753758

759+
it("routes mod+w to the terminal while focused and to the right panel otherwise", () => {
760+
const closeEvent = event({ key: "w", metaKey: true });
761+
assert.strictEqual(
762+
resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {
763+
platform: "MacIntel",
764+
context: { terminalFocus: true },
765+
}),
766+
"terminal.close",
767+
);
768+
assert.strictEqual(
769+
resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {
770+
platform: "MacIntel",
771+
context: { terminalFocus: false },
772+
}),
773+
"rightPanel.close",
774+
);
775+
});
776+
754777
it("resolves a custom right panel maximize binding", () => {
755778
const keybindings = compile([
756779
{

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
PullRequestListState,
1212
SourceControlProviderKind,
1313
} from "@t3tools/contracts";
14+
import { useAtomValue } from "@effect/atom-react";
1415
import { createFileRoute, useNavigate } from "@tanstack/react-router";
1516
import {
1617
ArrowDownUpIcon,
@@ -34,6 +35,7 @@ import {
3435
import {
3536
useCallback,
3637
useEffect,
38+
useEffectEvent,
3739
useMemo,
3840
useRef,
3941
useState,
@@ -107,7 +109,10 @@ import {
107109
} from "../components/WorkspaceBreadcrumb";
108110
import { WorkspacePageContainer } from "../components/WorkspacePageContainer";
109111
import { WorkspacePageHeader } from "../components/WorkspacePageHeader";
112+
import { isCommandPaletteOpen } from "../commandPaletteBus";
110113
import { isElectron } from "../env";
114+
import { resolveShortcutCommand } from "../keybindings";
115+
import { isTerminalFocused } from "../lib/terminalFocus";
111116
import { PanelLayoutControls } from "../components/chat/PanelLayoutControls";
112117
import { Button } from "../components/ui/button";
113118
import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../components/ui/menu";
@@ -135,6 +140,7 @@ import {
135140
} from "../state/pullRequests";
136141
import { useAtomCommand } from "../state/use-atom-command";
137142
import { cn } from "~/lib/utils";
143+
import { primaryServerKeybindingsAtom } from "~/state/server";
138144
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
139145

140146
export interface PullRequestsSearch extends PullRequestListPreferences {
@@ -285,6 +291,7 @@ function PullRequestsRouteView() {
285291
const statsPolicy: PullRequestStatsPolicy =
286292
sort === "ready" || sort === "largest" || sort === "smallest" ? "eager" : "visible";
287293
const navigate = useNavigate({ from: Route.fullPath });
294+
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
288295
const { environments } = useEnvironments();
289296
// Every connected environment that has said it can list pull requests. Sorted, so the query
290297
// keys, the scope key and the stored snapshot all read the same whichever order the
@@ -1888,6 +1895,26 @@ function PullRequestsRouteView() {
18881895
selectSurfaceInUrl(null);
18891896
};
18901897

1898+
// This page has no ChatView, so the shared panel handles `rightPanel.close`
1899+
// itself. With nothing open the event falls through to its native meaning.
1900+
const closeActiveSurfaceFromShortcut = useEffectEvent((event: KeyboardEvent) => {
1901+
if (activePullRequestSurface === null) return;
1902+
event.preventDefault();
1903+
event.stopPropagation();
1904+
if (!event.repeat) closeSurface(activePullRequestSurface);
1905+
});
1906+
useEffect(() => {
1907+
const onKeyDown = (event: KeyboardEvent) => {
1908+
if (event.defaultPrevented || isCommandPaletteOpen()) return;
1909+
const command = resolveShortcutCommand(event, keybindings, {
1910+
context: { terminalFocus: isTerminalFocused() },
1911+
});
1912+
if (command === "rightPanel.close") closeActiveSurfaceFromShortcut(event);
1913+
};
1914+
window.addEventListener("keydown", onKeyDown);
1915+
return () => window.removeEventListener("keydown", onKeyDown);
1916+
}, [keybindings]);
1917+
18911918
return (
18921919
<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground">
18931920
<div className="relative flex min-h-0 flex-1">

‎docs/user/keybindings.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ successful pick; its hover glow and badge preview the element and color family t
5252
`rightPanel.toggleMaximized` maximizes or restores the open right panel. It has no default shortcut,
5353
so add one in **Settings** → **Keybindings** if you want to use it.
5454

55+
`rightPanel.close` closes the active right panel tab and defaults to `mod+w`. Press it again to close
56+
the next tab. With the terminal focused, `mod+w` closes the terminal instead, and with nothing left
57+
to close it closes the desktop window as before. Browsers reserve `mod+w` for closing their own tab
58+
and never pass it to the page, so in a browser rebind this command (and `terminal.close`) to a
59+
shortcut the browser leaves alone, such as `alt+w`.
60+
5561
`thread.copyReference` copies the active thread's pull request link, or its thread ID when no pull
5662
request is available. Its default shortcut is `mod+shift+c`, and it does not replace terminal copy
5763
while the terminal has focus.

‎packages/contracts/src/keybindings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
5959
"terminal.close",
6060
"rightPanel.toggle",
6161
"rightPanel.toggleMaximized",
62+
"rightPanel.close",
6263
"diff.toggle",
6364
"preview.toggle",
6465
"preview.refresh",

‎packages/shared/src/keybindings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
2626
{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },
2727
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },
2828
{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },
29+
{ key: "mod+w", command: "rightPanel.close", when: "!terminalFocus" },
2930
{ key: "mod+d", command: "diff.toggle", when: "!terminalFocus" },
3031
{ key: "mod+shift+j", command: "preview.toggle" },
3132
{ key: "mod+r", command: "preview.refresh", when: "previewFocus" },

0 commit comments

Comments
 (0)