@@ -1266,10 +1266,6 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
1266
1266
let text = doc. text ( ) ;
1267
1267
let selections = doc. selection ( view. id ) ;
1268
1268
let primary = selections. primary ( ) ;
1269
- let rel_path = doc
1270
- . relative_path ( )
1271
- . map ( |path| path. parent ( ) . unwrap ( ) . to_path_buf ( ) )
1272
- . unwrap_or_default ( ) ;
1273
1269
1274
1270
let paths: Vec < _ > = if selections. len ( ) == 1 && primary. len ( ) == 1 {
1275
1271
// Secial case: if there is only one one-width selection, try to detect the
@@ -1323,14 +1319,35 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
1323
1319
. collect ( )
1324
1320
} ;
1325
1321
1322
+ let doc_path = doc
1323
+ . relative_path ( )
1324
+ . map ( |path| path. parent ( ) . unwrap ( ) . to_path_buf ( ) )
1325
+ . unwrap_or_default ( ) ;
1326
+
1327
+ let mut search_paths = vec ! [ doc_path] ;
1328
+
1329
+ let cwd = helix_stdx:: env:: current_working_dir ( ) ;
1330
+ if cwd. exists ( ) {
1331
+ search_paths. push ( cwd) ;
1332
+ }
1333
+ // FIXME: Also include project root? Or just use project root, not cwd?
1334
+
1326
1335
for sel in paths {
1327
1336
if let Ok ( url) = Url :: parse ( & sel) {
1328
1337
open_url ( cx, url, action) ;
1329
1338
continue ;
1330
1339
}
1331
1340
1332
- let path = expand_tilde ( Cow :: from ( PathBuf :: from ( sel) ) ) ;
1333
- let path = & rel_path. join ( path) ;
1341
+ let selpath = expand_tilde ( Cow :: from ( PathBuf :: from ( sel) ) ) ;
1342
+ let paths: Vec < _ > = search_paths. iter ( ) . map ( |sp| sp. join ( & selpath) ) . collect ( ) ;
1343
+ let existing: Vec < _ > = paths. iter ( ) . filter ( |p| p. exists ( ) ) . collect ( ) ;
1344
+
1345
+ let path = if !existing. is_empty ( ) {
1346
+ existing. first ( ) . unwrap ( )
1347
+ } else {
1348
+ paths. first ( ) . unwrap ( )
1349
+ } ;
1350
+
1334
1351
if path. is_dir ( ) {
1335
1352
let picker = ui:: file_picker ( path. into ( ) , & cx. editor . config ( ) ) ;
1336
1353
cx. push_layer ( Box :: new ( overlaid ( picker) ) ) ;
0 commit comments