Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocompletion for paths with period #5175

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,30 @@ pub mod completers {
use ignore::WalkBuilder;
use std::path::Path;

let is_tilde = input.starts_with('~') && input.len() == 1;
let is_tilde = input == "~";
let path = helix_core::path::expand_tilde(Path::new(input));

let (dir, file_name) = if input.ends_with(std::path::MAIN_SEPARATOR) {
(path, None)
} else {
let file_name = path
.file_name()
.and_then(|file| file.to_str().map(|path| path.to_owned()));

let path = match path.parent() {
Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
// Path::new("h")'s parent is Some("")...
_ => std::env::current_dir().expect("couldn't determine current directory"),
let is_period = (input.ends_with((format!("{}.", std::path::MAIN_SEPARATOR)).as_str())
&& input.len() > 2)
|| input == ".";
let file_name = if is_period {
Some(String::from("."))
} else {
path.file_name()
.and_then(|file| file.to_str().map(|path| path.to_owned()))
};

let path = if is_period {
path
} else {
match path.parent() {
Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
// Path::new("h")'s parent is Some("")...
_ => std::env::current_dir().expect("couldn't determine current directory"),
}
};

(path, file_name)
Expand Down