on master help sign in
fix: Don't internally use relative paths in the buffer picker

Fixes #619

commit1d45f50781f34bccf29a3e4f576cc48651038b09 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 24 Aug 2021, 09:56 (5 years ago) parente1c9f13
2 files changed+14−13
helix-term/src/commands.rs+5−4 helix-view/src/document.rs+9−9
helix-term/src/commands.rs+5−4
@@ -2288,16 +2288,17 @@ fn buffer_picker(cx: &mut Context) {
22882288 cx.editor
22892289 .documents
22902290 .iter()
2291− .map(|(id, doc)| (id, doc.relative_path()))
2291+ .map(|(id, doc)| (id, doc.path().cloned()))
22922292 .collect(),
22932293 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);
22952296 match path.as_ref().and_then(|path| path.to_str()) {
22962297 Some(path) => {
22972298 if *id == current {
2298− format!("{} (*)", path).into()
2299+ format!("{} (*)", &path).into()
22992300 } else {
2300− path.into()
2301+ path.to_owned().into()
23012302 }
23022303 }
23032304 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> {
398398 Ok(normalize_path(&path))
399399}
400400
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+
401409use helix_lsp::lsp;
402410use url::Url;
403411
@@ -936,15 +944,7 @@ impl Document {
936944 }
937945
938946 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| {
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− })
947+ self.path.as_deref().map(relative_path)
948948 }
949949
950950 // pub fn slice<R>(&self, range: R) -> RopeSlice where R: RangeBounds {