Remove "./" prefix for file path completions (#5387)

This commit is contained in:
Richard 2022-04-30 23:54:04 +02:00 committed by GitHub
parent f16401152b
commit 07893e01c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,7 +128,11 @@ pub fn file_path_completion(
entry.ok().and_then(|entry| {
let mut file_name = entry.file_name().to_string_lossy().into_owned();
if matches(&partial, &file_name, match_algorithm) {
let mut path = format!("{}{}", base_dir_name, file_name);
let mut path = if is_current_dir(&base_dir_name) {
file_name.to_string()
} else {
format!("{}{}", base_dir_name, file_name)
};
if entry.path().is_dir() {
path.push(SEP);
file_name.push(SEP);
@ -158,3 +162,7 @@ pub fn file_path_completion(
pub fn matches(partial: &str, from: &str, match_algorithm: MatchAlgorithm) -> bool {
match_algorithm.matches_str(&from.to_ascii_lowercase(), &partial.to_ascii_lowercase())
}
fn is_current_dir(base_dir: &str) -> bool {
base_dir == format!(".{}", SEP)
}