fix(mobile): natural sort in the mobile file explorer

Mobile re-sorted host readDir results with bare localeCompare, undoing
the host funnel's natural order (round-2 review). Reuse the shared
comparator and pin the order in the mobile suite.
This commit is contained in:
Brennan Benson
2026-07-30 07:33:51 -07:00
parent abc8c8bcb3
commit 2db52df770
2 changed files with 14 additions and 1 deletions
+12
View File
@@ -34,6 +34,18 @@ describe('file-tree', () => {
])
})
it('orders numbered names naturally, matching the desktop explorer', () => {
const cache: DirectoryCache = {
'': { entries: [entry('100 - b.txt'), entry('9 - c.txt'), entry('99 - a.txt')] }
}
expect(flattenDirectoryCache(cache, new Set()).map((row) => row.id)).toEqual([
'file:9 - c.txt',
'file:99 - a.txt',
'file:100 - b.txt'
])
})
it('mirrors desktop default browse exclusions while keeping dotfiles visible', () => {
const cache: DirectoryCache = {
'': {
+2 -1
View File
@@ -1,5 +1,6 @@
// Pure tree projection for the mobile file explorer. Mobile mirrors desktop
// browse semantics by flattening cached files.readDir results as folders open.
import { compareFileNames } from '../../../src/shared/file-name-sort'
export type MobileDirEntry = {
name: string
@@ -118,7 +119,7 @@ function compareDirectoryEntries(a: MobileDirEntry, b: MobileDirEntry): number {
if (a.isDirectory !== b.isDirectory) {
return a.isDirectory ? -1 : 1
}
return a.name.localeCompare(b.name)
return compareFileNames(a.name, b.name)
}
export function shouldIncludeMobileFileExplorerEntry(entry: MobileDirEntry): boolean {