diff options
author | Blaž Hrastnik | 2021-08-03 00:29:03 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-08-03 00:30:51 +0000 |
commit | adb5d842ba3ff7e539a77de54a0a8db3018a3844 (patch) | |
tree | 2f5ed4521b2af545f05956c1e666a16c2687eb93 /helix-term/src | |
parent | b3aefe18cd32b931431c4a6145f4eeef3abdef5c (diff) |
Use nicer filepaths instead of URIs in goto picker
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7403f5b2..cc2c2cca 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2497,6 +2497,8 @@ fn goto_impl( align_view(doc, view, Align::Center); } + let cwdir = std::env::current_dir().expect("couldn't determine current directory"); + match locations.as_slice() { [location] => { jump_to(editor, location, offset_encoding, Action::Replace); @@ -2507,8 +2509,23 @@ fn goto_impl( _locations => { let picker = ui::Picker::new( locations, - |location| { - let file = location.uri.as_str(); + move |location| { + let file: Cow<'_, str> = (location.uri.scheme() == "file") + .then(|| { + location + .uri + .to_file_path() + .map(|path| { + // strip root prefix + path.strip_prefix(&cwdir) + .map(|path| path.to_path_buf()) + .unwrap_or(path) + }) + .ok() + .and_then(|path| path.to_str().map(|path| path.to_owned().into())) + }) + .flatten() + .unwrap_or_else(|| location.uri.as_str().into()); let line = location.range.start.line; format!("{}:{}", file, line).into() }, |