Skip to content

Commit 2fba743

Browse files
committed
fix(web): match repo-relative prefixes on Windows paths
1 parent b1e954b commit 2fba743

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,9 @@ function useChatMarkdownState({
25812581
}
25822582
// A real child folder named like the project keeps the literal path.
25832583
const paths = new Set(result.value.entries.map((entry) => entry.path));
2584-
return !paths.has(workspaceRelativePath) && paths.has(strippedPath) ? strippedPath : null;
2584+
return !paths.has(workspaceRelativePath.replaceAll("\\", "/")) && paths.has(strippedPath)
2585+
? strippedPath
2586+
: null;
25852587
},
25862588
[cwd, environmentId, searchProjectEntries],
25872589
);

‎apps/web/src/workspaceBasenameLookup.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ describe("stripRepeatedWorkspacePrefix", () => {
103103
"a.md",
104104
);
105105
expect(stripRepeatedWorkspacePrefix("physics\\a.md", "C:\\school\\physics")).toBe("a.md");
106+
expect(stripRepeatedWorkspacePrefix("physics\\a.md", "C:\\school\\Physics")).toBe("a.md");
107+
expect(stripRepeatedWorkspacePrefix("physics/a.md", "/school/Physics")).toBeNull();
106108
});
107109

108110
it("returns null when the path does not start with the project folder", () => {

‎apps/web/src/workspaceBasenameLookup.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isWindowsAbsolutePath } from "@t3tools/shared/path";
2+
13
// Enough hits to look past same-named neighbours (`ChatView.test.tsx`) without
24
// asking for a full listing on a single click.
35
export const WORKSPACE_BASENAME_LOOKUP_LIMIT = 25;
@@ -61,9 +63,12 @@ export function pickWorkspaceBasenameMatch(
6163
export function stripRepeatedWorkspacePrefix(relativePath: string, cwd: string): string | null {
6264
const pathSegments = relativePath.split(/[\\/]+/);
6365
const cwdSegments = cwd.split(/[\\/]+/).filter(Boolean);
66+
const fold = isWindowsAbsolutePath(cwd)
67+
? (segment: string | undefined) => segment?.toLowerCase()
68+
: (segment: string | undefined) => segment;
6469
for (let count = Math.min(cwdSegments.length, pathSegments.length - 1); count > 0; count--) {
6570
const prefix = cwdSegments.slice(-count);
66-
if (prefix.every((segment, index) => segment === pathSegments[index])) {
71+
if (prefix.every((segment, index) => fold(segment) === fold(pathSegments[index]))) {
6772
return pathSegments.slice(count).join("/");
6873
}
6974
}

0 commit comments

Comments
 (0)