Skip to content

Commit 3b011c0

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(web): issues page answers the pull request page's keyboard (#1421)
> 🤖 claude/anthropic claude-opus-5-5 (high) ## What Changed The issues page answers the same keys as the Pull Requests page. | Key | Does | | --- | --- | | **Mod+F** | Focuses and selects the issue search | | **↓ in search** | Steps into the first row | | **↑ / ↓ on a row** | Moves between rows; ↑ on the first returns to search | | **Home / End** | First or last row | | **Enter** | Opens the focused row (unchanged) | | **Mod+W** | Closes the open issue (`rightPanel.close`) | | **Mod+Shift+C** | Copies the open issue's link (`thread.copyReference`) | - Close and copy read the user's keybindings, like the PR page - The thread's issues panel keeps arrow keys only; the thread owns the rest - The focus step is a pure helper with its own tests ## Why The page has no ChatView, so shared panel shortcuts did nothing there. A reader could search but never reach a result without the mouse. ## UI Changes | Row focus | Link copied | | --- | --- | | ![row focused](https://github.com/user-attachments/assets/baa34781-637d-44e3-a4a0-1aca36cb9fe2) | ![link copied](https://github.com/user-attachments/assets/2c032775-0cd6-4e90-b00b-221c8bc931ce) | **Before:** the same key sequence; nothing moves, so Enter opens nothing https://github.com/user-attachments/assets/f3bfd9a2-ec6e-40ac-9614-f5d5c5b55ed6 **After:** search, step down, open, copy, close, back to search https://github.com/user-attachments/assets/6e9d7db1-1992-4050-bec7-eb51c86785ff ## Checks ```text tsc --noEmit (apps/web) → exit 0 vp test run keyboard logic + issues page → exit 0 (9 tests) vp lint (changed files) → exit 0 vp run fork:ci → exit 0 ``` ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [x] I included before/after screenshots for any UI changes - [x] I included a video for animation/interaction changes Stacked on #1420. Opus 5.5 via Claude Code in T3 Code. ## Fork trailers Squashes: - 9ef260a feat(web): issues page answers the pull request page's keyboard (#1421) (#1421) - f60f824 fixup! feat(web): issues page answers the pull request page's keyboard (#1421) (#1421) - 9df341e6f0 feat(web): issues page answers the pull request page's keyboard (#1421) (#1421) - ec5efaeee3 fixup! feat(web): issues page answers the pull request page's keyboard (#1421) (#1421) Fork-Domain: github-issues Fork-Tier: qol Fork-Upstreamable: no
1 parent 8b12b0a commit 3b011c0

3 files changed

Lines changed: 180 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { gitHubIssueListFocusStep } from "./githubIssueKeyboard.logic";
4+
5+
describe("gitHubIssueListFocusStep", () => {
6+
it("steps from the search field into the first row and back", () => {
7+
expect(gitHubIssueListFocusStep("ArrowDown", "search", 3)).toBe(0);
8+
expect(gitHubIssueListFocusStep("ArrowUp", 0, 3)).toBe("search");
9+
});
10+
11+
it("clamps at the last row", () => {
12+
expect(gitHubIssueListFocusStep("ArrowDown", 1, 3)).toBe(2);
13+
expect(gitHubIssueListFocusStep("ArrowDown", 2, 3)).toBe(2);
14+
});
15+
16+
it("jumps to either end from a row, but leaves Home and End to the field's caret", () => {
17+
expect(gitHubIssueListFocusStep("Home", 2, 3)).toBe(0);
18+
expect(gitHubIssueListFocusStep("End", 0, 3)).toBe(2);
19+
expect(gitHubIssueListFocusStep("Home", "search", 3)).toBeNull();
20+
expect(gitHubIssueListFocusStep("ArrowUp", "search", 3)).toBeNull();
21+
});
22+
23+
it("handles nothing when there are no rows or the key is not a list key", () => {
24+
expect(gitHubIssueListFocusStep("ArrowDown", "search", 0)).toBeNull();
25+
expect(gitHubIssueListFocusStep("Enter", 1, 3)).toBeNull();
26+
});
27+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** Where list focus sits: the search field above the rows, or a row by its index. */
2+
export type GitHubIssueListFocus = "search" | number;
3+
4+
/**
5+
* Null when the key is not the list's to handle. The search field and rows read as one column:
6+
* ArrowDown leaves the field for the first row and ArrowUp on the first row returns to it. Home
7+
* and End jump within the rows only, because in the field they already move the caret.
8+
*/
9+
export function gitHubIssueListFocusStep(
10+
key: string,
11+
from: GitHubIssueListFocus,
12+
rowCount: number,
13+
): GitHubIssueListFocus | null {
14+
if (rowCount === 0) return null;
15+
if (from === "search") return key === "ArrowDown" ? 0 : null;
16+
switch (key) {
17+
case "ArrowDown":
18+
return Math.min(from + 1, rowCount - 1);
19+
case "ArrowUp":
20+
return from === 0 ? "search" : from - 1;
21+
case "Home":
22+
return 0;
23+
case "End":
24+
return rowCount - 1;
25+
default:
26+
return null;
27+
}
28+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import {
3+
type KeyboardEvent as ReactKeyboardEvent,
4+
type RefObject,
5+
useEffect,
6+
useEffectEvent,
7+
} from "react";
8+
9+
import { isCommandPaletteOpen } from "../../commandPaletteBus";
10+
import { isElectron } from "../../env";
11+
import { writeTextToClipboard } from "../../hooks/useCopyToClipboard";
12+
import { resolveShortcutCommand } from "../../keybindings";
13+
import { isTerminalFocused } from "../../lib/terminalFocus";
14+
import { primaryServerKeybindingsAtom } from "../../state/server";
15+
import { toastManager } from "../ui/toast";
16+
import { gitHubIssueListFocusStep, type GitHubIssueListFocus } from "./githubIssueKeyboard.logic";
17+
18+
const ROW_OPEN_SELECTOR = "[data-row-open]";
19+
20+
/** The page has no terminal, preview or model picker, so only focus and platform vary. */
21+
function getShortcutContext() {
22+
return {
23+
terminalFocus: isTerminalFocused(),
24+
terminalOpen: false,
25+
previewFocus: false,
26+
previewOpen: false,
27+
modelPickerOpen: false,
28+
isWeb: !isElectron,
29+
isDesktop: isElectron,
30+
};
31+
}
32+
33+
function copyIssueLink(url: string) {
34+
void writeTextToClipboard(url, "issue link").then(
35+
(didCopy) => {
36+
if (didCopy)
37+
toastManager.add({ type: "success", title: "Issue link copied", description: url });
38+
},
39+
(error) => {
40+
toastManager.add({
41+
type: "error",
42+
title: "Failed to copy issue link",
43+
description: error instanceof Error ? error.message : "An error occurred.",
44+
});
45+
},
46+
);
47+
}
48+
49+
/**
50+
* Matches the pull request page. The returned handler goes on an element holding the search
51+
* field and rows and walks focus with the arrow keys. With `page` set it also answers the
52+
* shortcuts ChatView owns elsewhere (Mod+F, panel close, copy reference); a thread's issues
53+
* panel leaves those to the thread around it.
54+
*/
55+
export function useGitHubIssueKeyboard({
56+
page,
57+
searchRef,
58+
openIssueUrl,
59+
onCloseIssue,
60+
}: {
61+
readonly page: boolean;
62+
/** Wraps the search field; its input is where Mod+F and ArrowUp off the first row land. */
63+
readonly searchRef: RefObject<HTMLElement | null>;
64+
/** The open issue's link, or null while none is open or it has not loaded. */
65+
readonly openIssueUrl: string | null;
66+
/** Closes the open issue, or null while none is open. */
67+
readonly onCloseIssue: (() => void) | null;
68+
}) {
69+
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
70+
71+
const onPageShortcut = useEffectEvent((event: KeyboardEvent) => {
72+
if (event.defaultPrevented || isCommandPaletteOpen()) return;
73+
if (
74+
event.key.toLowerCase() === "f" &&
75+
(event.metaKey || event.ctrlKey) &&
76+
!event.altKey &&
77+
!event.shiftKey
78+
) {
79+
event.preventDefault();
80+
const input = searchRef.current?.querySelector("input");
81+
input?.focus();
82+
input?.select();
83+
return;
84+
}
85+
const command = resolveShortcutCommand(event, keybindings, { context: getShortcutContext() });
86+
if (command === "rightPanel.close" && onCloseIssue !== null) {
87+
event.preventDefault();
88+
event.stopPropagation();
89+
if (!event.repeat) onCloseIssue();
90+
}
91+
if (command === "thread.copyReference" && openIssueUrl !== null) {
92+
event.preventDefault();
93+
event.stopPropagation();
94+
if (!event.repeat) copyIssueLink(openIssueUrl);
95+
}
96+
});
97+
// oxlint-disable-next-line t3code/react-effect-budget -- subscribes to document `keydown` DOM events for page-level shortcuts.
98+
useEffect(() => {
99+
if (!page) return;
100+
const onKeyDown = (event: KeyboardEvent) => onPageShortcut(event);
101+
document.addEventListener("keydown", onKeyDown);
102+
return () => document.removeEventListener("keydown", onKeyDown);
103+
}, [page]);
104+
105+
return (event: ReactKeyboardEvent<HTMLElement>) => {
106+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
107+
const target = event.target as HTMLElement;
108+
const rows = Array.from(event.currentTarget.querySelectorAll<HTMLElement>(ROW_OPEN_SELECTOR));
109+
const from: GitHubIssueListFocus | null = searchRef.current?.contains(target)
110+
? "search"
111+
: target.matches(ROW_OPEN_SELECTOR)
112+
? rows.indexOf(target)
113+
: null;
114+
if (from === null || from === -1) return;
115+
const to = gitHubIssueListFocusStep(event.key, from, rows.length);
116+
if (to === null) return;
117+
event.preventDefault();
118+
if (to === "search") {
119+
searchRef.current?.querySelector("input")?.focus();
120+
return;
121+
}
122+
rows[to]?.scrollIntoView({ block: "nearest" });
123+
rows[to]?.focus({ preventScroll: true });
124+
};
125+
}

0 commit comments

Comments
 (0)