TypeScript
fix(web): the ~ breadcrumb opens the home folder (#22412)
Onkar Pradip Jadhav69310dbd61a9
diff --git a/apps/web/src/components/files/filePath.test.ts b/apps/web/src/components/files/filePath.test.tsindex 22cb582493d..3bc371b5c1a 100644--- a/apps/web/src/components/files/filePath.test.ts+++ b/apps/web/src/components/files/filePath.test.ts@@ -1,6 +1,12 @@import { describe, expect, it } from "vite-plus/test";-import { fileBreadcrumbChildren, fileBreadcrumbs, retainedBreadcrumbTrail } from "./filePath";+import {+ breadcrumbPathOf,+ fileBreadcrumbChildren,+ fileBreadcrumbs,+ isListableHostFolder,+ retainedBreadcrumbTrail,+} from "./filePath";describe("fileBreadcrumbs", () => {it("starts host paths outside the workspace at the filesystem root", () => {@@ -20,6 +26,26 @@ describe("fileBreadcrumbs", () => {"\\\\server\\share\\report.md",]);});++ it("builds home-relative breadcrumbs with navigable folders", () => {+ expect(fileBreadcrumbs("t3code", "~/.claude/CLAUDE.md")).toEqual([+ { label: "~", path: "~/", kind: "directory" },+ { label: ".claude", path: "~/.claude", kind: "directory" },+ { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" },+ ]);+ expect(isListableHostFolder("~/")).toBe(true);+ expect(isListableHostFolder("~/.claude")).toBe(true);+ });++ it("keeps a project folder named ~ inside the project", () => {+ expect(fileBreadcrumbs("t3code", "~").map((crumb) => crumb.path)).toEqual(["", "~"]);+ });+});++describe("breadcrumbPathOf", () => {+ it("keeps the home root listable", () => {+ expect(breadcrumbPathOf("~/")).toBe("~/");+ });});describe("fileBreadcrumbChildren", () => {diff --git a/apps/web/src/components/files/filePath.ts b/apps/web/src/components/files/filePath.tsindex 76e10839bb2..f9f3c9a5ac4 100644--- a/apps/web/src/components/files/filePath.ts+++ b/apps/web/src/components/files/filePath.ts@@ -23,7 +23,8 @@ export function fileBreadcrumbs(projectName: string, relativePath: string): Filereturn {label: part,// A bare drive (`C:`) means the drive's current directory; its root is `C:\`.- path: /^[A-Za-z]:$/.test(path) ? `${path}\\` : path,+ // A bare `~` is not a host path; the home folder is `~/`.+ path: /^[A-Za-z]:$/.test(path) ? `${path}\\` : hostPath && path === "~" ? "~/" : path,kind: index === parts.length - 1 ? ("file" as const) : ("directory" as const),};}),