Skip to content

Commit 291bb58

Browse files
authored
Merge branch 'main' into t3code/fix-settings-ui-consistency
2 parents 22f7610 + 64fafbd commit 291bb58

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ describe("fileBreadcrumbChildren", () => {
6767
]);
6868
});
6969

70-
it("uses natural file-name ordering", () => {
71-
expect(fileBreadcrumbChildren(entries, "src/lib").map((entry) => entry.label)).toEqual([
70+
it("uses natural file-name ordering and preserves input order for equivalent names", () => {
71+
const files = ["file10.ts", "File2.ts", "file02.ts", "file2.ts"].map((name) => ({
72+
path: `src/lib/${name}`,
73+
kind: "file" as const,
74+
}));
75+
76+
expect(fileBreadcrumbChildren(files, "src/lib").map((entry) => entry.label)).toEqual([
77+
"File2.ts",
78+
"file02.ts",
7279
"file2.ts",
7380
"file10.ts",
7481
]);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function fileBreadcrumbChildren(
3636
entries: readonly ProjectEntry[],
3737
directoryPath: string,
3838
): FileBreadcrumbChild[] {
39+
let collator: Intl.Collator | undefined;
3940
const prefix = directoryPath ? `${directoryPath}/` : "";
4041
return entries
4142
.flatMap((entry) => {
@@ -46,10 +47,11 @@ export function fileBreadcrumbChildren(
4647
})
4748
.toSorted((left, right) => {
4849
if (left.kind !== right.kind) return left.kind === "directory" ? -1 : 1;
49-
return left.label.localeCompare(right.label, undefined, {
50+
collator ??= new Intl.Collator(undefined, {
5051
numeric: true,
5152
sensitivity: "base",
5253
});
54+
return collator.compare(left.label, right.label);
5355
});
5456
}
5557

0 commit comments

Comments
 (0)