Skip to content

Commit 1630dcc

Browse files
scratchyoneclaude
andcommitted
fix(web): mark the current crumb for paths with a trailing separator
A folder link such as `/tmp/demo/` or `src/` left no crumb marked current, because the crumbs are built without the trailing separator. Compare against the path written the way its own crumb names it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 16e5e41 commit 1630dcc

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎apps/web/src/components/files/FileBreadcrumbs.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { cn } from "~/lib/utils";
2222
import { isAbsolutePath } from "~/terminal-links";
2323

2424
import {
25+
breadcrumbPathOf,
2526
type FileBreadcrumb,
2627
fileBreadcrumbChildren,
2728
fileBreadcrumbParent,
@@ -304,7 +305,8 @@ export function FileBreadcrumbs(props: FileBreadcrumbsProps) {
304305
() => fileBreadcrumbs(props.projectName, props.trail),
305306
[props.projectName, props.trail],
306307
);
307-
const currentIndex = breadcrumbs.findIndex((crumb) => crumb.path === props.relativePath);
308+
const currentPath = breadcrumbPathOf(props.relativePath);
309+
const currentIndex = breadcrumbs.findIndex((crumb) => crumb.path === currentPath);
308310

309311
return (
310312
<nav aria-label="File path" className="flex h-full">

‎apps/web/src/components/files/filePath.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vite-plus/test";
22

33
import {
4+
breadcrumbPathOf,
45
fileBreadcrumbChildren,
56
fileBreadcrumbParent,
67
fileBreadcrumbs,
@@ -48,6 +49,22 @@ describe("fileBreadcrumbs", () => {
4849
});
4950
});
5051

52+
describe("breadcrumbPathOf", () => {
53+
it.each([
54+
["", ""],
55+
["src", "src"],
56+
["src/", "src"],
57+
["src//components", "src/components"],
58+
["/tmp/t3-demo/", "/tmp/t3-demo"],
59+
["/", "/"],
60+
["C:\\Users\\me\\", "C:\\Users\\me"],
61+
["C:\\", "C:\\"],
62+
["\\\\server\\share\\", "\\\\server\\share"],
63+
])("writes %j as its crumb names it", (path, expected) => {
64+
expect(breadcrumbPathOf(path)).toBe(expected);
65+
});
66+
});
67+
5168
describe("fileBreadcrumbChildren", () => {
5269
const entries = [
5370
{ path: "README.md", kind: "file" as const },

‎apps/web/src/components/files/filePath.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export function fileBreadcrumbs(projectName: string, relativePath: string): File
3636
];
3737
}
3838

39+
/**
40+
* `relativePath` written the way its own crumb names it, so a link with a
41+
* trailing or repeated separator still finds its crumb.
42+
*/
43+
export function breadcrumbPathOf(relativePath: string): string {
44+
return fileBreadcrumbs("", relativePath).at(-1)?.path ?? relativePath;
45+
}
46+
3947
/**
4048
* Whether a host folder crumb names a directory the server can list. A UNC
4149
* server (`\\server`) is not one; its shares (`\\server\share`) are.

0 commit comments

Comments
 (0)