Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/web/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isTerminalSplitShortcut,
isTerminalToggleShortcut,
resolveShortcutCommand,
panelNavigationShortcutData,
shortcutLabelForCommand,
shortcutLabelsForCommand,
terminalNavigationShortcutData,
Expand Down Expand Up @@ -513,6 +514,34 @@ describe("terminalNavigationShortcutData", () => {
});
});

describe("panelNavigationShortcutData", () => {
it("maps Ctrl+Left to the left sidebar", () => {
assert.strictEqual(
panelNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true })),
"sidebar",
);
});

it("maps Ctrl+Right to the right panel", () => {
assert.strictEqual(
panelNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true })),
"right-panel",
);
});

it("ignores unsupported modifier combinations", () => {
assert.isNull(panelNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true })));
assert.isNull(panelNavigationShortcutData(event({ key: "ArrowRight", altKey: true })));
assert.isNull(panelNavigationShortcutData(event({ key: "ArrowLeft", shiftKey: true })));
});

it("ignores non-keydown events", () => {
assert.isNull(
panelNavigationShortcutData(event({ type: "keyup", key: "ArrowLeft", ctrlKey: true })),
);
});
});

describe("plus key parsing", () => {
it("matches the plus key shortcut", () => {
const plusBindings = compile([{ shortcut: modShortcut("+"), command: "terminal.toggle" }]);
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,26 @@ export function terminalNavigationShortcutData(

return null;
}

export type PanelNavigationShortcutTarget = "sidebar" | "right-panel";

export function panelNavigationShortcutData(
event: ShortcutEventLike,
): PanelNavigationShortcutTarget | null {
if (event.type !== undefined && event.type !== "keydown") {
return null;
}

if (event.metaKey || event.altKey || event.shiftKey || !event.ctrlKey) {
return null;
}

const key = normalizeEventKey(event.key);
if (key === "arrowleft") {
return "sidebar";
}
if (key === "arrowright") {
return "right-panel";
}
return null;
}
50 changes: 49 additions & 1 deletion apps/web/src/routes/_chat.$threadId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import {
} from "react";
import { RightPanelHeader } from "~/components/RightPanelHeader";
import { WorkspacePanel } from "~/components/WorkspacePanel";
import { Sidebar, SidebarInset, SidebarProvider, SidebarRail } from "~/components/ui/sidebar";
import {
Sidebar,
SidebarInset,
SidebarProvider,
SidebarRail,
useSidebar,
} from "~/components/ui/sidebar";
import { WorkspaceFileTree } from "~/components/WorkspaceFileTree";
import { useChatWidgetStore } from "../chatWidgetStore";
import { useCodeViewerStore } from "../codeViewerStore";
Expand All @@ -24,6 +30,8 @@ import { useDiffViewerStore } from "../diffViewerStore";
import { isMobileShell } from "../env";
import { useClientMode } from "../hooks/useClientMode";
import { useTheme } from "../hooks/useTheme";
import { isTerminalFocused } from "../lib/terminalFocus";
import { panelNavigationShortcutData } from "../keybindings";
import { useRightPanelStore } from "../rightPanelStore";
import { useSimulationViewerStore } from "../simulationViewerStore";
import { useStore } from "../store";
Expand Down Expand Up @@ -169,6 +177,7 @@ const RightPanelSheet = (props: { open: boolean; onClose: () => void; children:
function ChatThreadRouteView() {
const threadsHydrated = useStore((store) => store.threadsHydrated);
const navigate = useNavigate();
const { toggleSidebar } = useSidebar();
const threadId = Route.useParams({
select: (params) => ThreadId.makeUnsafe(params.threadId),
});
Expand Down Expand Up @@ -228,6 +237,45 @@ function ChatThreadRouteView() {
closeSimulationStore();
}, [closeSimulationStore]);

useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
if (event.defaultPrevented) return;
if (event.repeat) return;
if (isTerminalFocused()) return;

const target = event.target;
if (target instanceof HTMLElement) {
if (
target.tagName === "INPUT" ||
target.tagName === "TEXTAREA" ||
target.isContentEditable
) {
return;
}
}

const shortcutTarget = panelNavigationShortcutData(event);
if (shortcutTarget === null) return;

event.preventDefault();
event.stopPropagation();

if (shortcutTarget === "sidebar") {
toggleSidebar();
return;
}

if (rightPanelOpen) {
closeRightPanel();
} else {
openRightPanel();
}
};

window.addEventListener("keydown", onWindowKeyDown);
return () => window.removeEventListener("keydown", onWindowKeyDown);
}, [closeRightPanel, openRightPanel, rightPanelOpen, toggleSidebar]);

// ── Sync sub-panel opens → right panel tab ────────────────────────
// When code viewer opens (or a new file is activated), switch to workspace tab.
useEffect(() => {
Expand Down
Loading