mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
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
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user