From 55464314bbfdc0e468fd541594f1b1363d2fe940 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sat, 5 Dec 2026 00:49:35 +0800 Subject: [PATCH] fix(github): fix issue browse assignee filter, list keyboard navigation, and edge cases --- src/features/github/create/CreatePanel.tsx | 10 +- src/features/github/index.ts | 4 +- src/features/github/issues/IssueEditor.tsx | 24 +- src/features/github/issues/Issues.module.css | 11 +- .../github/issues/IssuesToolWindow.tsx | 24 +- src/features/github/issues/actions.ts | 15 +- src/features/github/issues/api.ts | 56 +++-- src/features/github/issues/input.ts | 30 ++- src/features/github/issues/issues.test.tsx | 227 +++++++++++++++++- src/features/github/issues/usePages.ts | 24 +- 10 files changed, 365 insertions(+), 60 deletions(-) diff --git a/src/features/github/create/CreatePanel.tsx b/src/features/github/create/CreatePanel.tsx index 0b1c57ade3..7dbf70ff43 100644 --- a/src/features/github/create/CreatePanel.tsx +++ b/src/features/github/create/CreatePanel.tsx @@ -24,7 +24,8 @@ import { T, type MenuItem, } from "@/ui"; -import { issueForBranch } from "../issues/input"; +import { connectedRoot } from "../data/repository"; +import { hasClosingReference, issueForBranch } from "../issues/input"; import { openPullRequest } from "../toolwindow/open"; import { ChangesPanel } from "./ChangesPanel"; import { DirectionSelector } from "./DirectionSelector"; @@ -109,7 +110,10 @@ function TextPanel() { const templateLoading = useCreatePr((s) => s.templateLoading); const direction = useCreatePr((s) => s.direction); const head = direction?.headBranch; - const number = direction && head?.kind === "local" ? issueForBranch(direction.baseRepo, head.name) : null; + const number = + direction && head?.kind === "local" + ? issueForBranch({ ...direction.baseRepo, root: direction.baseRepo.root ?? connectedRoot() }, head.name) + : null; const closing = number ? `Closes #${number}` : null; return (
@@ -120,7 +124,7 @@ function TextPanel() { value={title} onChange={(e) => setTitle(e.target.value)} /> - {closing && !templateLoading && !description.split("\n").includes(closing) && ( + {closing && number && !templateLoading && !hasClosingReference(description, number) && (
); - const comments = page.items.flatMap((item) => item.comments.nodes); - const seen = new Set(comments.map((c) => c.id)); + const seen = new Set(); + const comments: IssueComment[] = []; + for (const item of page.items) { + for (const c of item.comments.nodes) { + if (seen.has(c.id)) continue; + seen.add(c.id); + comments.push(c); + } + } return (
@@ -72,7 +79,18 @@ function Discussion({ connection, number }: { connection: GHConnection; number: {issue.assignees.nodes.map((u) => ( @{u.login} ))} - void page.refresh()} /> diff --git a/src/features/github/issues/Issues.module.css b/src/features/github/issues/Issues.module.css index 2d8c0567cb..fa5e0e868f 100644 --- a/src/features/github/issues/Issues.module.css +++ b/src/features/github/issues/Issues.module.css @@ -16,15 +16,13 @@ min-width: 0; } .repo { + flex: 1; min-width: 0; overflow: hidden; + color: var(--fg-secondary); text-overflow: ellipsis; white-space: nowrap; } -.repo { - flex: 1; - color: var(--fg-secondary); -} .filters, .metadata { flex-wrap: wrap; @@ -58,3 +56,8 @@ color: var(--fg-secondary); overflow-wrap: anywhere; } +.error { + color: var(--danger); + font-size: var(--fs-small); + overflow-wrap: anywhere; +} diff --git a/src/features/github/issues/IssuesToolWindow.tsx b/src/features/github/issues/IssuesToolWindow.tsx index 7e423dfeef..8d7f8fb8f7 100644 --- a/src/features/github/issues/IssuesToolWindow.tsx +++ b/src/features/github/issues/IssuesToolWindow.tsx @@ -2,14 +2,17 @@ import { useCallback, useState, type MouseEvent } from "react"; import { useRowHeight } from "@/ui/density"; import { editorService } from "@/workbench/contributions"; import { tx } from "@/platform/i18n"; +import { isImeKey } from "@/platform/ime"; import { Button, EmptyState, Icon, IconButton, List, SearchField, Select, T } from "@/ui"; import { nameWithOwner, repositoryKey, useGhRepository, type GHConnection } from "../data/repository"; import { GithubConnectionGate } from "../toolwindow/GithubConnectionGate"; -import { issueList, type IssueStateFilter } from "./api"; +import { issueList, type IssueRow, type IssueStateFilter } from "./api"; import { issueInput } from "./input"; import { usePages } from "./usePages"; import styles from "./Issues.module.css"; +const issueKey = (item: IssueRow) => item.number; + export function IssuesToolWindow() { const connection = useGhRepository((s) => s.connection); return ( @@ -29,14 +32,21 @@ function IssuesList({ connection }: { connection: GHConnection }) { const [term, setTerm] = useState(""); const [state, setState] = useState("OPEN"); const [mine, setMine] = useState(false); + const [selectedNumber, setSelectedNumber] = useState(null); const fetchPage = useCallback( (cursor: string | null) => issueList(connection.coordinates, term, state, mine ? connection.currentUser.login : null, cursor), [connection, term, state, mine], ); - const page = usePages(fetchPage); + const page = usePages(fetchPage, issueKey); const rowHeight = useRowHeight(44); const exact = /^#\d+$/.test(term); + const activeIndex = page.items.length + ? Math.max( + 0, + page.items.findIndex((i) => i.number === selectedNumber), + ) + : -1; return (
@@ -55,7 +65,7 @@ function IssuesList({ connection }: { connection: GHConnection }) { if (!v.trim()) setTerm(""); }} onKeyDown={(e) => { - if (e.key === "Enter") setTerm(text.trim()); + if (e.key === "Enter" && !isImeKey(e.nativeEvent)) setTerm(text.trim()); }} />
@@ -80,6 +90,8 @@ function IssuesList({ connection }: { connection: GHConnection }) { rowHeight={rowHeight} items={page.items} getKey={(i) => String(i.number)} + activeIndex={activeIndex} + onActiveChange={(i) => setSelectedNumber(page.items[i]?.number ?? null)} className={styles.list} aria-label="GitHub Issues" onActivate={(row, _i, event) => { @@ -96,7 +108,11 @@ function IssuesList({ connection }: { connection: GHConnection }) { )} empty={page.error ? null : } /> - {page.error &&
{page.error}
} + {page.error && ( +
+ {page.error} +
+ )} {(page.next || page.error) && (