From 1d45f50781f34bccf29a3e4f576cc48651038b09 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 24 Aug 2021 09:56:09 +0900 Subject: fix: Don't internally use relative paths in the buffer picker Fixes #619 --- helix-view/src/document.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'helix-view/src') diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index ff0c8bf4..b38a94ab 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -398,6 +398,14 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result { Ok(normalize_path(&path)) } +pub fn relative_path(mut path: &Path) -> PathBuf { + let cwdir = std::env::current_dir().expect("couldn't determine current directory"); + if path.is_absolute() { + path = path.strip_prefix(cwdir).unwrap_or(path) + }; + fold_home_dir(path) +} + use helix_lsp::lsp; use url::Url; @@ -936,15 +944,7 @@ impl Document { } pub fn relative_path(&self) -> Option { - let cwdir = std::env::current_dir().expect("couldn't determine current directory"); - - self.path.as_ref().map(|path| { - let mut path = path.as_path(); - if path.is_absolute() { - path = path.strip_prefix(cwdir).unwrap_or(path) - }; - fold_home_dir(path) - }) + self.path.as_deref().map(relative_path) } // pub fn slice(&self, range: R) -> RopeSlice where R: RangeBounds { -- cgit v1.2.3-70-g09d2