From be8fc77cf112db30dc0c7e75bc9ffc2e67dbfa5d Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 31 Aug 2026 00:17:42 -0700 Subject: [PATCH] fix(renderer): preserve collapsed combined-diff tree boundaries --- .../combined-diff-file-tree-model.ts | 8 ++++++- .../combined-diff-file-tree.test.ts | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-model.ts b/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-model.ts index e9688169454..a0b12ad7510 100644 --- a/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-model.ts +++ b/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-model.ts @@ -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) } diff --git a/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree.test.ts b/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree.test.ts index 751959ee9b7..63209d37de3 100644 --- a/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree.test.ts +++ b/src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree.test.ts @@ -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) + }) })