on master help sign in
Fix autocompletion for paths with period (#5175)
c4b0eb8Dylan Bulfin
helix-term/src/ui/mod.rs+19−9
@@ -463,20 +463,30 @@ pub mod completers {
463 use ignore::WalkBuilder;
463 use ignore::WalkBuilder;
464 use std::path::Path;
464 use std::path::Path;
465
465
466− let is_tilde = input.starts_with('~') && input.len() == 1;
466+ let is_tilde = input == "~";
467 let path = helix_core::path::expand_tilde(Path::new(input));
467 let path = helix_core::path::expand_tilde(Path::new(input));
468
468
469 let (dir, file_name) = if input.ends_with(std::path::MAIN_SEPARATOR) {
469 let (dir, file_name) = if input.ends_with(std::path::MAIN_SEPARATOR) {
470 (path, None)
470 (path, None)
471 } else {
471 } else {
472− let file_name = path
472+ let is_period = (input.ends_with((format!("{}.", std::path::MAIN_SEPARATOR)).as_str())
473+ && input.len() > 2)
474+ || input == ".";
473− .file_name()
475+ let file_name = if is_period {
476+ Some(String::from("."))
477+ } else {
478+ path.file_name()
474− .and_then(|file| file.to_str().map(|path| path.to_owned()));
479+ .and_then(|file| file.to_str().map(|path| path.to_owned()))
475−
480+ };
481+
482+ let path = if is_period {
483+ path
484+ } else {
476− let path = match path.parent() {
485+ match path.parent() {
477− Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
486+ Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
478− // Path::new("h")'s parent is Some("")...
487+ // Path::new("h")'s parent is Some("")...
479− _ => std::env::current_dir().expect("couldn't determine current directory"),
488+ _ => std::env::current_dir().expect("couldn't determine current directory"),
489+ }
480 };
490 };
481
491
482 (path, file_name)
492 (path, file_name)