on master help sign in
Use nicer filepaths instead of URIs in goto picker
commitadb5d842ba3ff7e539a77de54a0a8db3018a3844 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 3 Aug 2021, 09:29 (5 years ago) parentb3aefe1
1 file changed+19−2
helix-term/src/commands.rs+19−2
helix-term/src/commands.rs+19−2
@@ -2497,6 +2497,8 @@ fn goto_impl(
24972497 align_view(doc, view, Align::Center);
24982498 }
24992499
2500+ let cwdir = std::env::current_dir().expect("couldn't determine current directory");
2501+
25002502 match locations.as_slice() {
25012503 [location] => {
25022504 jump_to(editor, location, offset_encoding, Action::Replace);
@@ -2507,8 +2509,23 @@ fn goto_impl(
25072509 _locations => {
25082510 let picker = ui::Picker::new(
25092511 locations,
2510− |location| {
2511− let file = location.uri.as_str();
2512+ move |location| {
2513+ let file: Cow<'_, str> = (location.uri.scheme() == "file")
2514+ .then(|| {
2515+ location
2516+ .uri
2517+ .to_file_path()
2518+ .map(|path| {
2519+ // strip root prefix
2520+ path.strip_prefix(&cwdir)
2521+ .map(|path| path.to_path_buf())
2522+ .unwrap_or(path)
2523+ })
2524+ .ok()
2525+ .and_then(|path| path.to_str().map(|path| path.to_owned().into()))
2526+ })
2527+ .flatten()
2528+ .unwrap_or_else(|| location.uri.as_str().into());
25122529 let line = location.range.start.line;
25132530 format!("{}:{}", file, line).into()
25142531 },