Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(review): keep file focus inside the review list

Linuxdazhao816888010661
diff --git a/apps/desktop/src/components/workpanel/ReviewHistoryPanel.tsx b/apps/desktop/src/components/workpanel/ReviewHistoryPanel.tsx
index 831f166ee..061a35fe6 100644
--- a/apps/desktop/src/components/workpanel/ReviewHistoryPanel.tsx
+++ b/apps/desktop/src/components/workpanel/ReviewHistoryPanel.tsx
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
import type { ReviewChangesPage, ReviewContextLines, ReviewTurnsPage } from "@pi-desktop/shared";
import { api } from "../../lib/api";
import { groupReviewFiles, readReviewPages } from "../../lib/review-history";
-import { useReviewFocusRequest } from "../../lib/review-focus-request";
+import { scrollReviewToAnchor, useReviewFocusRequest } from "../../lib/review-focus-request";
import { readReviewContextLines, rememberReviewContextLines } from "../../lib/review-preferences";
import { useAppStore } from "../../stores/app-store";
import { Button, Select } from "../ui";
@@ -52,8 +52,10 @@ export function ReviewHistoryPanel({ sessionId }: { sessionId: string }) {
const files = useMemo(() => groupReviewFiles(result.changes), [result]);
useEffect(() => {
if (loading || !selection.snapshotId) return;
- scroller.current?.querySelector<HTMLElement>(`[data-review-snapshots~="${CSS.escape(selection.snapshotId)}"]`)
- ?.scrollIntoView({ block: "start" });
+ scrollReviewToAnchor(
+ scroller.current,
+ `[data-review-snapshots~="${CSS.escape(selection.snapshotId)}"]`,
+ );
}, [files, loading, selection]);
const older = async () => {
if (catalog.nextBefore === undefined || paging) return;
diff --git a/apps/desktop/src/components/workpanel/ReviewTab.tsx b/apps/desktop/src/components/workpanel/ReviewTab.tsx
index aaae9f596..3fc4d0809 100644
--- a/apps/desktop/src/components/workpanel/ReviewTab.tsx
+++ b/apps/desktop/src/components/workpanel/ReviewTab.tsx
@@ -1,7 +1,7 @@
import { ReviewHistoryPanel } from "./ReviewHistoryPanel";
import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
-import { useReviewFocusRequest } from "../../lib/review-focus-request";
+import { scrollReviewToAnchor, useReviewFocusRequest } from "../../lib/review-focus-request";
import { reviewChangesFromMessages, summarizeReviewChanges } from "../../lib/workspace-review";
import { useAppStore } from "../../stores/app-store";
import { IconDiff } from "../icons";
@@ -55,9 +55,7 @@ function LegacyReviewTab() {
useEffect(() => {
if (!focus) return;
- scrollRef.current
- ?.querySelector<HTMLElement>(`[data-snapshot-id="${CSS.escape(focus.anchor)}"]`)
- ?.scrollIntoView({ block: "start" });
+ scrollReviewToAnchor(scrollRef.current, `[data-snapshot-id="${CSS.escape(focus.anchor)}"]`);
}, [focus]);
if (entries.length === 0) {
diff --git a/apps/desktop/src/lib/review-focus-request.ts b/apps/desktop/src/lib/review-focus-request.ts
index ffe79d011..dc06a6dde 100644
--- a/apps/desktop/src/lib/review-focus-request.ts
+++ b/apps/desktop/src/lib/review-focus-request.ts
@@ -44,3 +44,10 @@ function subscribe(listener: () => void): () => void {
export function useReviewFocusRequest(): ReviewFocusRequest | null {
return useSyncExternalStore(subscribe, currentReviewFocusRequest, () => null);
}
+
+export function scrollReviewToAnchor(scroller: HTMLElement | null, selector: string): void {
+ const anchor = scroller?.querySelector<HTMLElement>(selector);
+ if (!scroller || !anchor) return;
+ // Ancestor scrolling can move the app shell and hide the window chrome.
+ scroller.scrollTop += anchor.getBoundingClientRect().top - scroller.getBoundingClientRect().top;
+}
diff --git a/apps/desktop/test/turn-changes-card.test.mjs b/apps/desktop/test/turn-changes-card.test.mjs
index e59f7168a..bc91163b5 100644
--- a/apps/desktop/test/turn-changes-card.test.mjs
+++ b/apps/desktop/test/turn-changes-card.test.mjs
@@ -211,5 +211,12 @@ test("the card stays borderless and the Review tab honors focus requests", async
);
assert.match(reviewTab, /useReviewFocusRequest\(\)/);
assert.match(reviewTab, /openRequest=\{/);
- assert.match(reviewTab, /scrollIntoView/);
+ const historyPanel = await readFile(
+ new URL("../src/components/workpanel/ReviewHistoryPanel.tsx", import.meta.url),
+ "utf8",
+ );
+ assert.match(reviewTab, /scrollReviewToAnchor\(\s*scrollRef\.current,/);
+ assert.match(historyPanel, /scrollReviewToAnchor\(\s*scroller\.current,/);
+ assert.doesNotMatch(reviewTab, /scrollIntoView/);
+ assert.doesNotMatch(historyPanel, /scrollIntoView/);
});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index fb4b56e06..07da49ca2 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1038,6 +1038,9 @@ pending action cards remain reachable outside a hidden process. See
| Message-scoped review snapshot | Each successful workspace Write/Edit renders as one tool-level review row (`ReviewChangeCard`) carrying that message's added/modified/deleted status and explicit addition/deletion totals. The row itself is the file header — Git-style status letter (`A`/`M`/`D`), path, addition/deletion counts, disclosure caret — with no separate generic tool row above it, so the file header appears exactly once. It keeps the tool-row rhythm with no card border, status rail, icon plate, or status pill; hover fill is the only row chrome, and a rolled-back change is struck through. Its hunks sit in the diff body directly beneath that header behind the row's expandable disclosure: every review row (inline and in the Review tab) is collapsed by default, and the user expands it on demand. The diff body's action row keeps hash-guarded rollback and adds Copy for the hunks. The card remains after a Git commit, never becomes a bottom/global entry, and does not leak into another session's transcript. |
| Per-turn changed files | A completed reply (same mount condition as the reply plugin slots, so never while streaming and never after a failed turn) whose turn recorded at least one workspace review change shows one read-only `TurnChangesCard` below its answer and above `entryExtra` blocks (D674). It is built only from that turn's message-owned review records: one row per path in first-touched order, counts summed across edits, status `D` when the turn ends by deleting the file, else `A` if any edit created it, else `M`; a file whose every edit was rolled back stays listed, struck through, with the state in its accessible name. The card starts collapsed: its full-width header remains visible with a disclosure chevron, `Changes this turn`, the file count, and the summed `+`/`−`. Clicking the header or activating it with Enter/Space toggles the file list and its Review link without opening Review; `aria-expanded` and `aria-controls` expose the state, and hidden details are not keyboard-focusable. Each turn retains its own explicit choice through the existing session-scoped transcript disclosure mechanism and uses the shared scroll anchor. When expanded, up to four files use relaxed 25px rows; more switch to dense 21px rows and add the directory count; rows past 12 fold into `+N more` plus a link that opens Review. The card is one `--ds-tile` surface with no border or rules. Clicking a row opens the originating session's Review tab, scrolls to that file's first recorded change, and expands its changes there — the card has no diff body or rollback of its own. A turn without workspace writes renders nothing. |
+Focusing a file from the per-turn summary scrolls within the Review list.
+The window chrome and conversation viewport stay in place.
+
### 4.5 Accessibility
- `role="log"` for transcript container
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 7a0131836..2312682ab 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -19956,6 +19956,9 @@ Scenario: E2E-REVIEW-ROUNDS (local desktop, implemented)
isolated profile; verify both the checked menu option and actual diff context
retain that choice. Missing/invalid/blocked storage is unit-covered by
`apps/desktop/test/review-preferences.test.mjs`.
+- Open several files from the per-turn summary with enough Review content to
+ scroll. Each target comes into view inside Review while the conversation and
+ work-panel headers stay visible and the window content reaches the bottom edge.
- Expected: latest skips no-edit rounds; delegates belong to their original user
round; all file records are accessible; old/new numbers and bounded immutable context
agree; one gutter uses old numbers for deletions and new numbers otherwise;