fix(app): focus the matching review navigation arrow (#59920)

This commit is contained in:
usrnk1
2026-10-29 09:58:03 +01:00
committed by GitHub
Unverified
parent 2fc371657b
commit 509332627c
2 changed files with 54 additions and 1 deletions
@@ -1351,6 +1351,49 @@ test("video files stream into the viewer behind a loading state, open into the p
expect(await page.evaluate(() => document.fullscreenElement)).toBeNull()
})
test("review file navigation focuses the arrow for the keyboard direction", async ({ page }) => {
await openSession(page, {
name: "ReviewArrowFocus",
vcsDiff: [fileDiff("src/alpha.ts"), fileDiff("src/beta.ts"), fileDiff("src/gamma.ts")],
seed: {
panes: { ses_reviewarrowfocus: { review: true } },
storage: {
...reviewTabs("C:/OpenCode/ReviewArrowFocus", "ses_reviewarrowfocus"),
"opencode.global.dat:review-panel-v2": { sidebarOpened: false },
},
},
})
const panel = page.locator("#review-panel")
const file = panel.locator('[data-slot="session-review-v2-file-name"]')
const previous = panel.getByRole("button", { name: "Previous file", exact: true })
const next = panel.getByRole("button", { name: "Next file", exact: true })
await expect(file).toHaveText("alpha.ts")
await previous.click()
await expect(file).toHaveText("gamma.ts")
await page.keyboard.press("ArrowRight")
await expect(file).toHaveText("alpha.ts")
await expect(next).toBeFocused()
await page.keyboard.press("Enter")
await expect(file).toHaveText("beta.ts")
await page.keyboard.press("ArrowLeft")
await expect(file).toHaveText("alpha.ts")
await expect(previous).toBeFocused()
await next.click()
await expect(file).toHaveText("beta.ts")
await expect(next).toBeFocused()
const home = page.getByRole("button", { name: "Home", exact: true })
await home.focus()
await page.keyboard.press("ArrowRight")
await expect(file).toHaveText("gamma.ts")
await expect(home).toBeFocused()
await page.keyboard.press("ArrowLeft")
await expect(file).toHaveText("beta.ts")
await expect(home).toBeFocused()
})
test("restores review state and the side-panel tab per session", async ({ page }) => {
const sessions = [
{ id: "ses_review_state_a", title: "Alpha review state" },
@@ -154,6 +154,8 @@ export function SessionReviewV2Sidebar(props: SessionReviewV2SidebarProps) {
export function SessionReviewV2(props: SessionReviewV2Props) {
const i18n = useI18n()
const locale = useLocale()
let previousButton: HTMLButtonElement | undefined
let nextButton: HTMLButtonElement | undefined
createEffect(() => {
getWorkerPool()
@@ -208,11 +210,17 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
if (target instanceof HTMLElement && (target.isContentEditable || target.closest("input, textarea, select"))) return
if (!props.hasDiffs || !canCycle()) return
const file = event.key === previousKey() ? prev() : next()
const previous = event.key === previousKey()
const file = previous ? prev() : next()
if (!file) return
const active = document.activeElement
event.preventDefault()
cycle(file)
if (active !== previousButton && active !== nextButton) return
;(previous ? previousButton : nextButton)?.focus({ preventScroll: true })
})
const toolbarStart = () => (
@@ -242,6 +250,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
}
>
<IconButton
ref={previousButton}
icon={<Icon name="arrow-left" />}
variant="ghost"
size="small"
@@ -262,6 +271,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
}
>
<IconButton
ref={nextButton}
icon={<Icon name="arrow-right" />}
variant="ghost"
size="small"