Skip to content

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

fix(chat): scroll after file viewer renders

vastsa096c864d6411
diff --git a/apps/desktop/src/components/workpanel/FilesTab.tsx b/apps/desktop/src/components/workpanel/FilesTab.tsx
index 200adfcbc..5f5418231 100644
--- a/apps/desktop/src/components/workpanel/FilesTab.tsx
+++ b/apps/desktop/src/components/workpanel/FilesTab.tsx
@@ -227,14 +227,6 @@ export function FilesTab() {
setFileError(false);
try {
setFile(await api.fsRead(rel, mimeType));
- if (position?.line != null) {
- requestAnimationFrame(() => {
- const lineNode = viewerBodyRef.current?.querySelector(
- `[data-line="${position.line}"]`,
- );
- lineNode?.scrollIntoView({ block: "center" });
- });
- }
} catch {
setFileError(true);
}
@@ -242,6 +234,17 @@ export function FilesTab() {
[],
);
+ useEffect(() => {
+ if (!file || selectedLine == null) return;
+ const frame = requestAnimationFrame(() => {
+ const lineNode = viewerBodyRef.current?.querySelector(
+ `[data-line="${selectedLine}"]`,
+ );
+ lineNode?.scrollIntoView({ block: "center" });
+ });
+ return () => cancelAnimationFrame(frame);
+ }, [file, selectedLine]);
+
const openMp4 = useCallback(async () => {
if (!selected) return;
try {
diff --git a/apps/desktop/test/transcript-file-chips.test.mjs b/apps/desktop/test/transcript-file-chips.test.mjs
index df44d82f2..ae133e087 100644
--- a/apps/desktop/test/transcript-file-chips.test.mjs
+++ b/apps/desktop/test/transcript-file-chips.test.mjs
@@ -54,7 +54,9 @@ test("a file chip is routed by where the reference resolved, never optimisticall
assert.match(hook, /fileManagerPluginTab\(resolved\.path\)/);
assert.match(filesTab, /data-line=\{i \+ 1\}/);
assert.match(filesTab, /viewerBodyRef\.current\?\.querySelector/);
- assert.match(filesTab, /data-line="\$\{position\.line\}"/);
+ assert.match(filesTab, /if \(!file \|\| selectedLine == null\) return/);
+ assert.match(filesTab, /data-line="\$\{selectedLine\}"/);
+ assert.match(filesTab, /return \(\) => cancelAnimationFrame\(frame\)/);
assert.match(filesTab, /selectedLine === undefined/);
// Session scratch and attachment files live outside the plugin's project
// roots, and positioned references need the host viewer's line navigation.