on master help sign in
Fix autocompletion for paths with period (#5175)

* Bug fix Updated bug fix * Simplified conditionals * Switched to use path separator constant

commitc4b0eb835639d2c18d940cd0c55093a92169b432 authorDylan Bulfin <31492860+DylanBulfin@users.noreply.github.com> dateSun 8 Jan 2023, 21:25 (4 years ago) parentb368df5
1 file changed+19−9
helix-term/src/ui/mod.rs+19−9
helix-term/src/ui/mod.rs+19−9
@@ -463,20 +463,30 @@ pub mod completers {
463463 use ignore::WalkBuilder;
464464 use std::path::Path;
465465
466− let is_tilde = input.starts_with('~') && input.len() == 1;
466+ let is_tilde = input == "~";
467467 let path = helix_core::path::expand_tilde(Path::new(input));
468468
469469 let (dir, file_name) = if input.ends_with(std::path::MAIN_SEPARATOR) {
470470 (path, None)
471471 } else {
472− let file_name = path
473− .file_name()
474− .and_then(|file| file.to_str().map(|path| path.to_owned()));
475−
476− let path = match path.parent() {
477− Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
478− // Path::new("h")'s parent is Some("")...
479− _ => std::env::current_dir().expect("couldn't determine current directory"),
472+ let is_period = (input.ends_with((format!("{}.", std::path::MAIN_SEPARATOR)).as_str())
473+ && input.len() > 2)
474+ || input == ".";
475+ let file_name = if is_period {
476+ Some(String::from("."))
477+ } else {
478+ path.file_name()
479+ .and_then(|file| file.to_str().map(|path| path.to_owned()))
480+ };
481+
482+ let path = if is_period {
483+ path
484+ } else {
485+ match path.parent() {
486+ Some(path) if !path.as_os_str().is_empty() => path.to_path_buf(),
487+ // Path::new("h")'s parent is Some("")...
488+ _ => std::env::current_dir().expect("couldn't determine current directory"),
489+ }
480490 };
481491
482492 (path, file_name)