TypeScript
feat(web): mod+w closes the active right panel tab before the window (#9363)
Julius Marminged4bd8923ad8c
diff --git a/apps/server/src/keybindings.test.ts b/apps/server/src/keybindings.test.tsindex 079e7a14eda..6c32235c27f 100644--- a/apps/server/src/keybindings.test.ts+++ b/apps/server/src/keybindings.test.ts@@ -207,6 +207,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {assert.equal(defaultsByCommand.get("sidebar.toggle"), "mod+b");assert.equal(defaultsByCommand.get("rightPanel.toggle"), "mod+alt+b");assert.isFalse(defaultsByCommand.has("rightPanel.toggleMaximized"));+ assert.equal(defaultsByCommand.get("rightPanel.close"), "mod+w");assert.equal(defaultsByCommand.get("terminal.splitVertical"), "mod+shift+d");assert.equal(defaultsByCommand.get("modelPicker.jump.1"), "mod+1");assert.equal(defaultsByCommand.get("modelPicker.jump.9"), "mod+9");diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 1d76b4ae5d6..ca8f85dc315 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -5691,6 +5691,16 @@ function ChatViewContent(props: ChatViewProps) {return;}+ if (command === "rightPanel.close") {+ // Nothing open: leave the event alone so the shortcut keeps its+ // native meaning (close window on desktop, close tab in a browser).+ if (!activeRightPanelSurface) return;+ event.preventDefault();+ event.stopPropagation();+ if (!event.repeat) closeRightPanelSurface(activeRightPanelSurface);+ return;+ }+if (command === "terminal.split") {event.preventDefault();event.stopPropagation();@@ -5779,6 +5789,7 @@ function ChatViewContent(props: ChatViewProps) {terminalUiState.terminalOpen,terminalUiState.activeTerminalId,activeThreadId,+ closeRightPanelSurface,requestCloseTerminal,requestClosePanelTerminal,createNewTerminal,diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.tsindex 0f3fa825e44..8cbc4596652 100644--- a/apps/web/src/keybindings.test.ts+++ b/apps/web/src/keybindings.test.ts@@ -108,6 +108,11 @@ const DEFAULT_BINDINGS = compile([command: "terminal.close",whenAst: whenIdentifier("terminalFocus"),},+ {+ shortcut: modShortcut("w"),+ command: "rightPanel.close",+ whenAst: whenNot(whenIdentifier("terminalFocus")),+ },{shortcut: modShortcut("d"),command: "diff.toggle",@@ -751,6 +756,24 @@ describe("resolveShortcutCommand", () => {);});+ it("routes mod+w to the terminal while focused and to the right panel otherwise", () => {+ const closeEvent = event({ key: "w", metaKey: true });+ assert.strictEqual(+ resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {+ platform: "MacIntel",+ context: { terminalFocus: true },+ }),+ "terminal.close",+ );+ assert.strictEqual(+ resolveShortcutCommand(closeEvent, DEFAULT_BINDINGS, {+ platform: "MacIntel",+ context: { terminalFocus: false },+ }),+ "rightPanel.close",+ );+ });+it("resolves a custom right panel maximize binding", () => {const keybindings = compile([{diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsxindex 912366d14ab..09701423fae 100644--- a/apps/web/src/routes/_chat.pull-requests.tsx+++ b/apps/web/src/routes/_chat.pull-requests.tsx@@ -11,6 +11,7 @@ import type {PullRequestListState,SourceControlProviderKind,} from "@t3tools/contracts";+import { useAtomValue } from "@effect/atom-react";import { createFileRoute, useNavigate } from "@tanstack/react-router";import {ArrowDownUpIcon,@@ -34,6 +35,7 @@ import {import {useCallback,useEffect,+ useEffectEvent,useMemo,useRef,useState,@@ -107,7 +109,10 @@ import {} from "../components/WorkspaceBreadcrumb";import { WorkspacePageContainer } from "../components/WorkspacePageContainer";import { WorkspacePageHeader } from "../components/WorkspacePageHeader";+import { isCommandPaletteOpen } from "../commandPaletteBus";import { isElectron } from "../env";+import { resolveShortcutCommand } from "../keybindings";+import { isTerminalFocused } from "../lib/terminalFocus";import { PanelLayoutControls } from "../components/chat/PanelLayoutControls";import { Button } from "../components/ui/button";import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../components/ui/menu";@@ -135,6 +140,7 @@ import {} from "../state/pullRequests";import { useAtomCommand } from "../state/use-atom-command";import { cn } from "~/lib/utils";+import { primaryServerKeybindingsAtom } from "~/state/server";import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";export interface PullRequestsSearch extends PullRequestListPreferences {@@ -285,6 +291,7 @@ function PullRequestsRouteView() {const statsPolicy: PullRequestStatsPolicy =sort === "ready" || sort === "largest" || sort === "smallest" ? "eager" : "visible";const navigate = useNavigate({ from: Route.fullPath });+ const keybindings = useAtomValue(primaryServerKeybindingsAtom);const { environments } = useEnvironments();// Every connected environment that has said it can list pull requests. Sorted, so the query// keys, the scope key and the stored snapshot all read the same whichever order the@@ -1888,6 +1895,26 @@ function PullRequestsRouteView() {selectSurfaceInUrl(null);};+ // This page has no ChatView, so the shared panel handles `rightPanel.close`+ // itself. With nothing open the event falls through to its native meaning.+ const closeActiveSurfaceFromShortcut = useEffectEvent((event: KeyboardEvent) => {+ if (activePullRequestSurface === null) return;+ event.preventDefault();+ event.stopPropagation();+ if (!event.repeat) closeSurface(activePullRequestSurface);+ });+ useEffect(() => {+ const onKeyDown = (event: KeyboardEvent) => {+ if (event.defaultPrevented || isCommandPaletteOpen()) return;+ const command = resolveShortcutCommand(event, keybindings, {+ context: { terminalFocus: isTerminalFocused() },+ });+ if (command === "rightPanel.close") closeActiveSurfaceFromShortcut(event);+ };+ window.addEventListener("keydown", onKeyDown);+ return () => window.removeEventListener("keydown", onKeyDown);+ }, [keybindings]);+return (<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground"><div className="relative flex min-h-0 flex-1">diff --git a/docs/user/keybindings.md b/docs/user/keybindings.mdindex 4668ec64092..fe97eedadbc 100644--- a/docs/user/keybindings.md+++ b/docs/user/keybindings.md@@ -52,6 +52,12 @@ successful pick; its hover glow and badge preview the element and color family t`rightPanel.toggleMaximized` maximizes or restores the open right panel. It has no default shortcut,so add one in **Settings** → **Keybindings** if you want to use it.+`rightPanel.close` closes the active right panel tab and defaults to `mod+w`. Press it again to close+the next tab. With the terminal focused, `mod+w` closes the terminal instead, and with nothing left+to close it closes the desktop window as before. Browsers reserve `mod+w` for closing their own tab+and never pass it to the page, so in a browser rebind this command (and `terminal.close`) to a+shortcut the browser leaves alone, such as `alt+w`.+`thread.copyReference` copies the active thread's pull request link, or its thread ID when no pullrequest is available. Its default shortcut is `mod+shift+c`, and it does not replace terminal copywhile the terminal has focus.diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.tsindex fe3549d079a..71b2547e532 100644--- a/packages/contracts/src/keybindings.ts+++ b/packages/contracts/src/keybindings.ts@@ -59,6 +59,7 @@ export const STATIC_KEYBINDING_COMMANDS = ["terminal.close","rightPanel.toggle","rightPanel.toggleMaximized",+ "rightPanel.close","diff.toggle","preview.toggle","preview.refresh",diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.tsindex 939e88b7f0b..1107873c828 100644--- a/packages/shared/src/keybindings.ts+++ b/packages/shared/src/keybindings.ts@@ -26,6 +26,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [{ key: "mod+shift+d", command: "terminal.splitVertical", when: "terminalFocus" },{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },+ { key: "mod+w", command: "rightPanel.close", when: "!terminalFocus" },{ key: "mod+d", command: "diff.toggle", when: "!terminalFocus" },{ key: "mod+shift+j", command: "preview.toggle" },{ key: "mod+r", command: "preview.refresh", when: "previewFocus" },