Skip to content
Open
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
28 changes: 28 additions & 0 deletions src/browser/components/app-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
HoverCardContent,
} from "../ui/hover-card";
import { version } from "../../../package.json";
import { KeyboardShortcutsModal } from "./keyboard-shortcuts-modal";
import { matchesKey } from "@/browser/lib/shortcuts";

// ============================================================================
// App Shell - Tab-based Layout
Expand All @@ -40,6 +42,7 @@ export function AppShell() {
} = useTabContext();
const params = useParams<{ owner: string; repo: string; number: string }>();
const navigate = useNavigate();
const [shortcutsModalOpen, setShortcutsModalOpen] = useState(false);

// URL is the source of truth - sync URL → Tab
useEffect(() => {
Expand Down Expand Up @@ -116,6 +119,26 @@ export function AppShell() {
return () => window.removeEventListener("keydown", handleKeyDown);
}, [tabs, activeTabId, handleTabSelect, closeTab]);

// Handle ? key for keyboard shortcuts modal
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
const target = e.target as HTMLElement;
if (
target.tagName === "INPUT" ||
target.tagName === "TEXTAREA" ||
target.isContentEditable
) {
return;
}
if (matchesKey(e, "SHOW_SHORTCUTS")) {
e.preventDefault();
setShortcutsModalOpen(true);
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, []);

return (
<div className="h-screen flex flex-col overflow-hidden bg-background">
{/* Native-style Tab Bar */}
Expand Down Expand Up @@ -210,6 +233,11 @@ export function AppShell() {
</div>
)}
</div>

<KeyboardShortcutsModal
open={shortcutsModalOpen}
onOpenChange={setShortcutsModalOpen}
/>
</div>
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/browser/components/command-palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { cn } from "../cn";
import { usePRReviewSelector, usePRReviewStore } from "../contexts/pr-review";
import { Keycap, KeycapGroup } from "../ui/keycap";
import type { PullRequestFile } from "@/api/types";
import { matchesKey } from "@/browser/lib/shortcuts";

// ============================================================================
// Global Command Palette Context
Expand All @@ -44,7 +45,10 @@ export function CommandPaletteProvider({ children }: { children: ReactNode }) {
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
// Ctrl+K or Ctrl+P to open command palette
if ((e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "p")) {
if (
matchesKey(e, "OPEN_FILE_SEARCH_K") ||
matchesKey(e, "OPEN_FILE_SEARCH_P")
) {
e.preventDefault();
e.stopPropagation();
setOpen((prev) => !prev);
Expand Down
54 changes: 54 additions & 0 deletions src/browser/components/keyboard-shortcuts-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
} from "@/browser/ui/dialog";
import { KeycapGroup } from "@/browser/ui/keycap";
import { getShortcutsByCategory } from "@/browser/lib/shortcuts";

interface KeyboardShortcutsModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}

export function KeyboardShortcutsModal({
open,
onOpenChange,
}: KeyboardShortcutsModalProps) {
const categories = getShortcutsByCategory();

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-xl max-h-[85vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Keyboard Shortcuts</DialogTitle>
<DialogDescription className="sr-only">
A list of all available keyboard shortcuts
</DialogDescription>
</DialogHeader>
<div className="grid gap-6 pt-2">
{categories.map(({ category, shortcuts }) => (
<div key={category}>
<h3 className="text-sm font-medium text-muted-foreground mb-2">
{category}
</h3>
<div className="space-y-1.5">
{shortcuts.map((shortcut, idx) => (
<div
key={idx}
className="flex items-center justify-between py-1"
>
<span className="text-sm">{shortcut.description}</span>
<KeycapGroup keys={shortcut.keys} size="sm" />
</div>
))}
</div>
</div>
))}
</div>
</DialogContent>
</Dialog>
);
}
Loading