diff --git a/src/lib.rs b/src/lib.rs index 333db14..dab4beb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,14 +182,14 @@ impl<'a> Toipe { Key::Ctrl('r') => { return Ok(TestStatus::Restart); } - Key::Ctrl('w') => { + Key::Ctrl('w') | Key::Ctrl('h') => { + // delete space if it is a last char + if matches!(input.last(), Some(' ') | None) { + self.delete_last_char(&mut input, &original_text)?; + } // delete last word while !matches!(input.last(), Some(' ') | None) { - if input.pop().is_some() { - self.tui.replace_text( - Text::from(original_text[input.len()]).with_faint(), - )?; - } + self.delete_last_char(&mut input, &original_text)?; } } Key::Char(c) => { @@ -283,6 +283,18 @@ impl<'a> Toipe { Ok((to_restart, results)) } + fn delete_last_char( + &mut self, + input: &mut Vec, + original_text: &[char], + ) -> Result<(), ToipeError> { + if input.pop().is_some() { + self.tui + .replace_text(Text::from(original_text[input.len()]).with_faint())?; + } + Ok(()) + } + fn display_results( &mut self, results: ToipeResults,