on master help sign in
fix: Don't internally use relative paths in the buffer picker
1d45f50Blaž Hrastnik
helix-term/src/commands.rs+5−4
@@ -2288,16 +2288,17 @@ fn buffer_picker(cx: &mut Context) {
2288 cx.editor
2288 cx.editor
2289 .documents
2289 .documents
2290 .iter()
2290 .iter()
2291− .map(|(id, doc)| (id, doc.relative_path()))
2291+ .map(|(id, doc)| (id, doc.path().cloned()))
2292 .collect(),
2292 .collect(),
2293 move |(id, path): &(DocumentId, Option<PathBuf>)| {
2293 move |(id, path): &(DocumentId, Option<PathBuf>)| {
2294− // format_fn
2294+ use helix_view::document::relative_path;
2295+ let path = path.as_deref().map(relative_path);
2295 match path.as_ref().and_then(|path| path.to_str()) {
2296 match path.as_ref().and_then(|path| path.to_str()) {
2296 Some(path) => {
2297 Some(path) => {
2297 if *id == current {
2298 if *id == current {
2298− format!("{} (*)", path).into()
2299+ format!("{} (*)", &path).into()
2299 } else {
2300 } else {
2300− path.into()
2301+ path.to_owned().into()
2301 }
2302 }
2302 }
2303 }
2303 None => "[scratch buffer]".into(),
2304 None => "[scratch buffer]".into(),
helix-view/src/document.rs+9−9
@@ -398,6 +398,14 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
398 Ok(normalize_path(&path))
398 Ok(normalize_path(&path))
399}
399}
400
400
401+pub fn relative_path(mut path: &Path) -> PathBuf {
402+ let cwdir = std::env::current_dir().expect("couldn't determine current directory");
403+ if path.is_absolute() {
404+ path = path.strip_prefix(cwdir).unwrap_or(path)
405+ };
406+ fold_home_dir(path)
407+}
408+
401use helix_lsp::lsp;
409use helix_lsp::lsp;
402use url::Url;
410use url::Url;
403
411
@@ -936,15 +944,7 @@ impl Document {
936 }
944 }
937
945
938 pub fn relative_path(&self) -> Option<PathBuf> {
946 pub fn relative_path(&self) -> Option<PathBuf> {
939− let cwdir = std::env::current_dir().expect("couldn't determine current directory");
940−
941− self.path.as_ref().map(|path| {
947+ self.path.as_deref().map(relative_path)
942− let mut path = path.as_path();
943− if path.is_absolute() {
944− path = path.strip_prefix(cwdir).unwrap_or(path)
945− };
946− fold_home_dir(path)
947− })
948 }
948 }
949
949
950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {
950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {