aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-24 00:56:09 +0000
committerBlaž Hrastnik2021-08-24 00:56:09 +0000
commit1d45f50781f34bccf29a3e4f576cc48651038b09 (patch)
tree4308bba5e4efa8f865a5d363afcf0bf58d9f8a1e
parente1c9f132637bcf2406c7c1403ab3d8dfd882369e (diff)
fix: Don't internally use relative paths in the buffer picker
Fixes #619
-rw-r--r--helix-term/src/commands.rs9
-rw-r--r--helix-view/src/document.rs18
2 files changed, 14 insertions, 13 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 56e4f1b6..7434d4cd 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2288,16 +2288,17 @@ fn buffer_picker(cx: &mut Context) {
cx.editor
.documents
.iter()
- .map(|(id, doc)| (id, doc.relative_path()))
+ .map(|(id, doc)| (id, doc.path().cloned()))
.collect(),
move |(id, path): &(DocumentId, Option<PathBuf>)| {
- // format_fn
+ use helix_view::document::relative_path;
+ let path = path.as_deref().map(relative_path);
match path.as_ref().and_then(|path| path.to_str()) {
Some(path) => {
if *id == current {
- format!("{} (*)", path).into()
+ format!("{} (*)", &path).into()
} else {
- path.into()
+ path.to_owned().into()
}
}
None => "[scratch buffer]".into(),
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<PathBuf> {
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<PathBuf> {
- 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<R>(&self, range: R) -> RopeSlice where R: RangeBounds {