Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mark-sidebar-root-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

Label repo-root file runs with an in-place `./` sidebar header so root files remain visually distinct without changing review order.
4 changes: 2 additions & 2 deletions src/ui/AppHost.interactions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3299,8 +3299,8 @@ describe("App interactions", () => {
}

await act(async () => {
// Click inside the second file row in the left sidebar.
await setup.mockMouse.click(6, 4);
// Click inside the second file row below the repo-root group header.
await setup.mockMouse.click(6, 5);
});
await flush(setup);

Expand Down
11 changes: 10 additions & 1 deletion src/ui/components/ui-components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ describe("UI components", () => {
previousPath: "src/ui/Legacy.tsx",
stats: { additions: 0, deletions: 0 },
},
createTestDiffFile(
"root",
"zzz-root.ts",
"export const root = 1;\n",
"export const root = 2;\n",
),
];
const frame = await captureFrame(
<SidebarPane
Expand All @@ -453,11 +459,14 @@ describe("UI components", () => {
onSelectFile={() => {}}
/>,
36,
10,
12,
);

expect(frame).toContain("src/ui/");
expect(frame).toContain("src/core/");
expect(frame).toContain("./");
expect(frame).toContain(" zzz-root.ts");
expect(frame.indexOf("src/ui/")).toBeLessThan(frame.indexOf("./"));
expect(frame).toContain(" App.tsx");
expect(frame).toContain(" MenuDropdown.tsx");
expect(frame).toContain(" watch.ts");
Expand Down
26 changes: 26 additions & 0 deletions src/ui/lib/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ describe("files helpers", () => {
});
});

test("buildSidebarEntries marks each root-file run with an in-place ./ group", () => {
const files = [
createTestDiffFile({ id: "nested-a", path: "src/a.ts" }),
createTestDiffFile({ id: "root-a", path: "README.md" }),
createTestDiffFile({ id: "root-b", path: "package.json" }),
createTestDiffFile({ id: "nested-b", path: "test/b.ts" }),
createTestDiffFile({ id: "root-c", path: "LICENSE" }),
];

const labels = buildSidebarEntries(files).map((entry) =>
entry.kind === "group" ? entry.label : entry.name,
);

expect(labels).toEqual([
"src/",
"a.ts",
"./",
"README.md",
"package.json",
"test/",
"b.ts",
"./",
"LICENSE",
]);
});

test("fileLabelParts strips parser-added line endings from rename labels", () => {
const renamedAcrossDirectories = {
...createTestDiffFile({
Expand Down
21 changes: 9 additions & 12 deletions src/ui/lib/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,19 @@ export function filterReviewFiles(files: DiffFile[], query: string): DiffFile[]
/** Build the grouped sidebar entries while preserving the review stream order. */
export function buildSidebarEntries(files: DiffFile[]): SidebarEntry[] {
const entries: SidebarEntry[] = [];
let activeGroup: string | null = null;
let activeGroup: string | undefined;

files.forEach((file, index) => {
const path = sanitizeTerminalLine(normalizeDiffPath(file.path) ?? file.path);
const group = dirname(path);
const nextGroup = group === "." ? null : group;

if (nextGroup !== activeGroup) {
activeGroup = nextGroup;
if (activeGroup) {
entries.push({
kind: "group",
id: `group:${activeGroup}:${index}`,
label: `${activeGroup}/`,
});
}

if (group !== activeGroup) {
activeGroup = group;
entries.push({
kind: "group",
id: `group:${group}:${index}`,
label: group === "." ? "./" : `${group}/`,
});
}

const agentCommentCount = file.agent?.annotations.length ?? 0;
Expand Down