@@ -19,7 +19,17 @@ export function DialogSelectDirectory(props: DialogSelectDirectoryProps) {
1919 const dialog = useDialog ( )
2020
2121 const home = createMemo ( ( ) => sync . data . path . home )
22- const root = createMemo ( ( ) => sync . data . path . home || sync . data . path . directory )
22+
23+ function isAbsolutePath ( p : string ) {
24+ return p . startsWith ( "/" ) || / ^ [ a - z A - Z ] : [ \\ / ] / . test ( p )
25+ }
26+
27+ function getParentPath ( p : string ) {
28+ const normalized = p . replace ( / [ \\ / ] + $ / , "" )
29+ const lastSlash = Math . max ( normalized . lastIndexOf ( "/" ) , normalized . lastIndexOf ( "\\" ) )
30+ if ( lastSlash <= 0 ) return "/"
31+ return normalized . slice ( 0 , lastSlash )
32+ }
2333
2434 function join ( base : string | undefined , rel : string ) {
2535 const b = ( base ?? "" ) . replace ( / [ \\ / ] + $ / , "" )
@@ -29,61 +39,72 @@ export function DialogSelectDirectory(props: DialogSelectDirectoryProps) {
2939 return b + "/" + r
3040 }
3141
32- function display ( rel : string ) {
33- const full = join ( root ( ) , rel )
42+ function display ( fullPath : string ) {
3443 const h = home ( )
35- if ( ! h ) return full
36- if ( full === h ) return "~"
37- if ( full . startsWith ( h + "/" ) || full . startsWith ( h + "\\" ) ) {
38- return "~" + full . slice ( h . length )
44+ if ( ! h ) return fullPath
45+ if ( fullPath === h ) return "~"
46+ if ( fullPath . startsWith ( h + "/" ) || fullPath . startsWith ( h + "\\" ) ) {
47+ return "~" + fullPath . slice ( h . length )
3948 }
40- return full
49+ return fullPath
4150 }
4251
43- function normalizeQuery ( query : string ) {
52+ async function fetchDirs ( filter : string ) {
53+ const trimmed = filter . trim ( )
4454 const h = home ( )
4555
46- if ( ! query ) return query
47- if ( query . startsWith ( "~/" ) ) return query . slice ( 2 )
56+ // Determine search directory and query based on input
57+ let directory : string
58+ let query : string
4859
49- if ( h ) {
50- const lc = query . toLowerCase ( )
51- const hc = h . toLowerCase ( )
52- if ( lc === hc || lc . startsWith ( hc + "/" ) || lc . startsWith ( hc + "\\" ) ) {
53- return query . slice ( h . length ) . replace ( / ^ [ \\ / ] + / , "" )
60+ if ( isAbsolutePath ( trimmed ) ) {
61+ // Check if path ends with / - user wants to see directory contents
62+ if ( trimmed . endsWith ( "/" ) || trimmed . endsWith ( "\\" ) ) {
63+ directory = trimmed . replace ( / [ \\ / ] + $ / , "" )
64+ query = ""
65+ } else {
66+ // Absolute path without trailing slash: use parent directory, search for basename
67+ directory = getParentPath ( trimmed )
68+ const basename = trimmed . slice ( directory . length ) . replace ( / ^ [ \\ / ] + / , "" )
69+ query = basename
5470 }
71+ } else if ( trimmed . startsWith ( "~/" ) ) {
72+ // Home-relative path
73+ directory = h || "/"
74+ query = trimmed . slice ( 2 )
75+ } else {
76+ // Relative query: search in home
77+ directory = h || "/"
78+ query = trimmed
5579 }
5680
57- return query
58- }
59-
60- async function fetchDirs ( query : string ) {
61- const directory = root ( )
6281 if ( ! directory ) return [ ] as string [ ]
6382
6483 const results = await sdk . client . find
6584 . files ( { directory, query, type : "directory" , limit : 50 } )
6685 . then ( ( x ) => x . data ?? [ ] )
6786 . catch ( ( ) => [ ] )
6887
69- return results . map ( ( x ) => x . replace ( / [ \\ / ] + $ / , "" ) )
88+ // Results are relative to directory - convert to absolute paths
89+ return results . map ( ( x ) => {
90+ const rel = x . replace ( / [ \\ / ] + $ / , "" )
91+ return join ( directory , rel )
92+ } )
7093 }
7194
7295 const directories = async ( filter : string ) => {
73- const query = normalizeQuery ( filter . trim ( ) )
74- return fetchDirs ( query )
96+ return fetchDirs ( filter )
7597 }
7698
77- function resolve ( rel : string ) {
78- const absolute = join ( root ( ) , rel )
79- props . onSelect ( props . multiple ? [ absolute ] : absolute )
99+ function resolve ( absolutePath : string ) {
100+ props . onSelect ( props . multiple ? [ absolutePath ] : absolutePath )
80101 dialog . close ( )
81102 }
82103
83104 return (
84105 < Dialog title = { props . title ?? "Open project" } >
85106 < List
86- search = { { placeholder : "Search folders" , autofocus : true } }
107+ search = { { placeholder : "Search folders (use / for absolute paths) " , autofocus : true } }
87108 emptyMessage = "No folders found"
88109 items = { directories }
89110 key = { ( x ) => x }
@@ -92,17 +113,17 @@ export function DialogSelectDirectory(props: DialogSelectDirectoryProps) {
92113 resolve ( path )
93114 } }
94115 >
95- { ( rel ) => {
96- const path = display ( rel )
116+ { ( absolutePath ) => {
117+ const displayPath = display ( absolutePath )
97118 return (
98119 < div class = "w-full flex items-center justify-between rounded-md" >
99120 < div class = "flex items-center gap-x-3 grow min-w-0" >
100- < FileIcon node = { { path : rel , type : "directory" } } class = "shrink-0 size-4" />
121+ < FileIcon node = { { path : absolutePath , type : "directory" } } class = "shrink-0 size-4" />
101122 < div class = "flex items-center text-14-regular min-w-0" >
102123 < span class = "text-text-weak whitespace-nowrap overflow-hidden overflow-ellipsis truncate min-w-0" >
103- { getDirectory ( path ) }
124+ { getDirectory ( displayPath ) }
104125 </ span >
105- < span class = "text-text-strong whitespace-nowrap" > { getFilename ( path ) } </ span >
126+ < span class = "text-text-strong whitespace-nowrap" > { getFilename ( displayPath ) } </ span >
106127 </ div >
107128 </ div >
108129 </ div >
0 commit comments