on master help sign in
Use nicer filepaths instead of URIs in goto picker
adb5d84Blaž Hrastnik
helix-term/src/commands.rs+19−2
@@ -2497,6 +2497,8 @@ fn goto_impl(
2497 align_view(doc, view, Align::Center);
2497 align_view(doc, view, Align::Center);
2498 }
2498 }
2499
2499
2500+ let cwdir = std::env::current_dir().expect("couldn't determine current directory");
2501+
2500 match locations.as_slice() {
2502 match locations.as_slice() {
2501 [location] => {
2503 [location] => {
2502 jump_to(editor, location, offset_encoding, Action::Replace);
2504 jump_to(editor, location, offset_encoding, Action::Replace);
@@ -2507,8 +2509,23 @@ fn goto_impl(
2507 _locations => {
2509 _locations => {
2508 let picker = ui::Picker::new(
2510 let picker = ui::Picker::new(
2509 locations,
2511 locations,
2510− |location| {
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()
2511− let file = location.uri.as_str();
2528+ .unwrap_or_else(|| location.uri.as_str().into());
2512 let line = location.range.start.line;
2529 let line = location.range.start.line;
2513 format!("{}:{}", file, line).into()
2530 format!("{}:{}", file, line).into()
2514 },
2531 },