From ad0dde7232e3e760bcf8629a7e3bf3f30a0453ee Mon Sep 17 00:00:00 2001 From: Justine Pelletreau Date: Fri, 1 Dec 2023 11:58:10 +0100 Subject: [PATCH] Autocomplete to longest string when searching commands --- src/shell/autocomplete.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/shell/autocomplete.rs b/src/shell/autocomplete.rs index 731e3b6..b3614f8 100644 --- a/src/shell/autocomplete.rs +++ b/src/shell/autocomplete.rs @@ -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); }