fix(desktop): normalize picker root results

This commit is contained in:
LukeParkerDev 2026-06-08 08:34:15 +10:00
parent 0a34ca9b63
commit 96b2971c75
2 changed files with 5 additions and 2 deletions

View file

@ -65,8 +65,11 @@ test("centralizes file and directory selection policy", () => {
expect(directory.includeFiles).toBeFalse()
expect(directory.selection("/repo", "src/")).toBe("/repo/src")
expect(directory.selection("C:/Users/luke", "repos/")).toBe("C:\\Users\\luke\\repos")
expect(directory.selection("//Server/Share", "repo/")).toBe("\\\\Server\\Share\\repo")
expect(directory.navigation("/tmp")).toBe("/tmp")
expect(directory.result("/repo", "")).toBe("/repo")
expect(directory.result("C:/Users/luke", "")).toBe("C:\\Users\\luke")
expect(directory.result("//Server/Share/repo", "")).toBe("\\\\Server\\Share\\repo")
expect(directory.result("/repo", "", false)).toBeUndefined()
})

View file

@ -55,7 +55,7 @@ export function pickerMode(mode: "directory" | "file", base?: string) {
},
result(root: string, selected: string, valid = true) {
if (!valid) return
return selected || root || undefined
return selected || (root ? nativePickerPath(root) : undefined)
},
selection(root: string, path: string) {
return selectedTreePath(root, path, "directory")
@ -166,7 +166,7 @@ export function selectedTreePath(root: string, path: string, mode: "directory" |
export function nativePickerPath(path: string) {
const value = trimPickerPath(path)
if (/^[A-Za-z]:\//.test(value)) return value.replaceAll("/", "\\")
if (/^[A-Za-z]:\//.test(value) || value.startsWith("//")) return value.replaceAll("/", "\\")
return value
}
import { getFilename } from "@opencode-ai/core/util/path"