From ab62ae7e9633ec3d702d0d74fa258421ebfc2e3f Mon Sep 17 00:00:00 2001 From: Wooseong Kim <2222333+innocarpe@users.noreply.github.com> Date: Mon, 26 Oct 2026 19:50:58 +0900 Subject: [PATCH] fix(diff): keep the collapsed section header in view (#24466) Collapsing the section the View all diff viewport was inside kept the scroll anchor's within-section offset, which pointed into the removed body, so the structural restore landed on later sections. Pin the anchor to the section header before the collapse is published. Fixes #20665 --- .../editor/combined-diff/CombinedDiffViewer.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx b/src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx index c1ecbb9db3c..3c9c1b2d80b 100644 --- a/src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx +++ b/src/renderer/src/components/editor/combined-diff/CombinedDiffViewer.tsx @@ -167,7 +167,13 @@ export default function CombinedDiffViewer({ const toggleSection = useCallback( (index: number) => { - const shouldLoadAfterExpand = registry.sectionsRef.current[index]?.collapsed ?? false + const section = registry.sectionsRef.current[index] + const shouldLoadAfterExpand = section?.collapsed ?? false + const anchor = restore.scrollAnchorRef.current + if (section && !section.collapsed && anchor?.key === section.key) { + // The offset points into the body being removed; restore would land on later sections. + anchor.offset = 0 + } setSections((prev) => prev.map((s, i) => (i === index ? { ...s, collapsed: !s.collapsed } : s)) ) @@ -175,7 +181,7 @@ export default function CombinedDiffViewer({ registry.loadSchedulerRef.current.request(index) } }, - [registry.loadSchedulerRef, registry.sectionsRef] + [registry.loadSchedulerRef, registry.sectionsRef, restore.scrollAnchorRef] ) const treeNavigation = useCombinedDiffTreeNavigation({