Skip to content

Commit 1fef0f0

Browse files
ymansurozerclaude
andcommitted
fix: open each file scrolled to the top
Switching files never reset the diff pane's scroll position, so a tall next file inherited the previous file's scrollTop and opened mid-way down. Reset #diff.scrollTop after a genuine file/view switch (same-file re-renders still keep their scroll). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lj241sZMvCV2wAuH1A65Fm
1 parent 2196f67 commit 1fef0f0

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/ui/render.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,18 @@ async function renderCenter() {
512512
// Mount only this file's wrapper (replaceChildren detaches the previously-active wrapper —
513513
// it lives on in the Map — and removes any overview/markdown content). Skip when it's already
514514
// the sole child (a same-file re-render) so we don't detach/reattach and reset scroll.
515-
if (host.firstElementChild !== entry.wrapper || host.childElementCount !== 1)
516-
host.replaceChildren(entry.wrapper);
515+
const mountedNew = host.firstElementChild !== entry.wrapper || host.childElementCount !== 1;
516+
if (mountedNew) host.replaceChildren(entry.wrapper);
517517
entry.inst.setLineAnnotations?.(anns());
518518
await entry.inst.render({
519519
fileDiff: fd,
520520
containerWrapper: entry.wrapper,
521521
lineAnnotations: anns(),
522522
});
523+
// A genuine file/view switch starts at the top. #diff is the persistent scroll container, so
524+
// replaceChildren preserves its previous scrollTop — a tall next file would otherwise open
525+
// mid-scroll. A same-file re-render (a decision applied) skips this and keeps its scroll.
526+
if (mountedNew) host.scrollTop = 0;
523527
afterRender();
524528
// Evict least-recently-used instances beyond the cap.
525529
while (D.diffCache.size > DIFF_CACHE_CAP) {

0 commit comments

Comments
 (0)