From cf6a9961d185ae18e94d5eb399f46441d1574111 Mon Sep 17 00:00:00 2001 From: Justine Pelletreau Date: Thu, 16 Nov 2023 16:46:28 +0100 Subject: [PATCH] autocomplete fix ? --- src/lib.rs | 18 +++++++++--------- src/shell/autocomplete.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c2a8891..aa5207f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -408,23 +408,23 @@ pub mod shell { }; } + fn find_next_space(current_pos: &usize, max_pos: &usize, command: &String) -> usize { + let markers = vec![' ', '!', ',', ';', ':']; let mut steps: usize = 0; if *current_pos == *max_pos { return steps; } - for letter in command.chars().skip(*current_pos) { - //println!("L : {:?}, S : {:?} C: {:?} M {:?}", letter, steps, current_pos, max_pos); - //Skip if we start on a space - if steps == 0 && (letter == ' ' || letter == ',' || letter == ';') { - continue; - } else if letter != ' ' && *current_pos + steps < *max_pos { - steps += 1; - } else { + for letter in command.chars().skip(*current_pos+1) { + if markers.contains(&letter) { + if *current_pos + steps < *max_pos { steps += 1; } return steps; + } else { + steps += 1; } } let max: usize = (0 + max_pos) - current_pos; return max; } + fn handle_conf(stdout: &mut Stdout) -> SqishConf { let conf = match SqishConf::from_sqishrc() { @@ -614,7 +614,7 @@ pub mod shell { fn jmp_prev_word(elems: &mut TermElements) { let command_rev = elems.command.chars().rev().collect::(); - let curr_rev = elems.max_pos - elems.cur_pos + 1; + let curr_rev = elems.max_pos - elems.cur_pos; let steps = find_next_space(&curr_rev, &elems.max_pos, &command_rev); if steps > 0 { print!("{}", cursor::Left(steps as u16)); diff --git a/src/shell/autocomplete.rs b/src/shell/autocomplete.rs index 00c3a6c..1a259d4 100644 --- a/src/shell/autocomplete.rs +++ b/src/shell/autocomplete.rs @@ -104,7 +104,6 @@ impl Search { if res.len() < 1 { *&mut res = format!("{}{}", &self.command, &self.searchee); } - return (res, res_lines); } @@ -205,7 +204,12 @@ fn autocomplete_file(search: &Search) -> std::io::Result<(String, String)> { //Remote search... is annoying if !search.local_search { last_found = last_found.replace("./", ""); - return Ok((format!("{}{}{}", search.command, search.search_path.display(), last_found), String::new())); + //println!("{:?}", format!("{}{}", search.command, last_found)); + if nbr_found < 2 { + return Ok((format!("{}{}{}", search.command, search.search_path.display(), last_found), String::new())); + } else { + return Ok((format!("{}{}", search.command, last_found), all_res)); + } } last_found = last_found.replace("./", "");