fix(renderer): preserve collapsed combined-diff tree boundaries

This commit is contained in:
Neil
2026-08-31 15:51:06 -07:00
parent 0b73a66ca9
commit be8fc77cf1
2 changed files with 30 additions and 1 deletions
@@ -131,7 +131,13 @@ export function getViewedCombinedDiffTreeVisibility({
}
const names = [projected.source.name]
let compacted = projected
while (compacted.children.length === 1 && compacted.children[0]?.source.type === 'directory') {
// Keep a collapsed directory as a visible boundary; filtering must not compact it away and
// accidentally expose descendants that the user explicitly hid.
while (
!collapsedDirectoryKeys.has(compacted.source.key) &&
compacted.children.length === 1 &&
compacted.children[0]?.source.type === 'directory'
) {
compacted = compacted.children[0]
names.push(compacted.source.name)
}
@@ -192,4 +192,27 @@ describe('CombinedDiffFileTree navigation mapping', () => {
})
expect(compactedDirectory && visibility.visibleFileCounts.get(compactedDirectory.key)).toBe(1)
})
it('preserves a collapsed directory boundary while filtering viewed siblings', () => {
const entries: GitBranchChangeEntry[] = [
{ path: 'src/a/one.ts', status: 'modified' },
{ path: 'src/b/two.ts', status: 'modified' }
]
const roots = buildCombinedDiffBranchTreeRoots('branch', entries)
const visibility = getViewedCombinedDiffTreeVisibility({
roots,
collapsedDirectoryKeys: new Set(['dir::combined-branch::src']),
mode: 'branch',
viewedSectionKeys: new Set(['combined-branch:src/b/two.ts'])
})
expect(visibility.rows).toEqual([
expect.objectContaining({
type: 'directory',
key: 'dir::combined-branch::src',
path: 'src'
})
])
expect(visibility.visibleFileCount).toBe(1)
})
})