Autocomplete to longest string when searching commands

This commit is contained in:
Justine Pelletreau 2023-12-01 11:58:10 +01:00
parent 56e5d4e63d
commit ad0dde7232

View File

@ -220,7 +220,7 @@ fn autocomplete_file(search: &Search) -> std::io::Result<(String, String)> {
}
}
last_found = last_found.replace("./", "");
//last_found = last_found.replace("./", "");
//Otherwise... Handling the return as gracefully as I can
let mut return_val = String::new();
@ -266,7 +266,9 @@ fn autocomplete_cmd(input: &String, search: &Search) -> (String, String) {
} else {
let mut all_res = String::new();
let mut counter = 0;
let mut bins = Vec::new();
for path in found_bins {
//Show 40 results max
if counter < 40 {
let buff = String::from(path
.iter()
@ -274,6 +276,7 @@ fn autocomplete_cmd(input: &String, search: &Search) -> (String, String) {
.unwrap()
.to_str()
.unwrap());
*&mut bins.push(buff.clone());
let res_line = format!("* {}\r\n", buff);
all_res.push_str(&res_line);
counter += 1;
@ -283,8 +286,8 @@ fn autocomplete_cmd(input: &String, search: &Search) -> (String, String) {
break;
}
}
let first_res = String::from(input);
let ret_line = format!("{}{}", &search.command, first_res);
let longest = find_common_chars(bins);
let ret_line = format!("{}", longest);
return(ret_line, all_res);
}