aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorWojciech Kępka2021-06-18 06:19:34 +0000
committerGitHub2021-06-18 06:19:34 +0000
commit41b07486ad935ad820dd4ba210457a03c95e1145 (patch)
treef7c8bb69d3398d222e26a627d8b70627b73237f8 /helix-term/src/ui
parent42142cf680197a2076b9fa8ec864b91e67068082 (diff)
Fix expansion of `~` (#284)
* Fix expansion of `~`, dont use directory relative to cwd. * Add `expand_tilde` * Bring back `canonicalize_path`, use `expand_tilde` to `normalize` * Make `:open ~` completion work * Fix clippy * Fold home dir into tilde in Document `realitve_path`
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/mod.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index b2274d06..39e11cd6 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -126,10 +126,11 @@ pub mod completers {
use ignore::WalkBuilder;
use std::path::{Path, PathBuf};
- let path = Path::new(input);
+ let is_tilde = input.starts_with('~') && input.len() == 1;
+ let path = helix_view::document::expand_tilde(Path::new(input));
let (dir, file_name) = if input.ends_with('/') {
- (path.into(), None)
+ (path, None)
} else {
let file_name = path
.file_name()
@@ -154,7 +155,16 @@ pub mod completers {
let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
let path = entry.path();
- let mut path = path.strip_prefix(&dir).unwrap_or(path).to_path_buf();
+ let mut path = if is_tilde {
+ // if it's a single tilde an absolute path is displayed so that when `TAB` is pressed on
+ // one of the directories the tilde will be replaced with a valid path not with a relative
+ // home directory name.
+ // ~ -> <TAB> -> /home/user
+ // ~/ -> <TAB> -> ~/first_entry
+ path.to_path_buf()
+ } else {
+ path.strip_prefix(&dir).unwrap_or(path).to_path_buf()
+ };
if is_dir {
path.push("");
@@ -184,7 +194,7 @@ pub mod completers {
})
.collect();
- let range = ((input.len() - file_name.len())..);
+ let range = ((input.len().saturating_sub(file_name.len()))..);
matches.sort_unstable_by_key(|(_file, score)| Reverse(*score));
files = matches