From c9a89340c58ba4cd2aea72f12ffec255bad87ffd Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Sat, 16 Sep 2023 07:36:52 +0100 Subject: [PATCH] chore(clafrica): update - chore: We prefer stop listening before any operation - test: We don't need to wait before release the key --- clafrica/src/lib.rs | 3 +-- clafrica/src/processor.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clafrica/src/lib.rs b/clafrica/src/lib.rs index a00b1d4..c5f9291 100644 --- a/clafrica/src/lib.rs +++ b/clafrica/src/lib.rs @@ -152,7 +152,6 @@ mod tests { $( thread::sleep($delay); rdev::simulate(&KeyPress($key)).unwrap(); - thread::sleep($delay); rdev::simulate(&KeyRelease($key)).unwrap(); )* ); @@ -209,7 +208,7 @@ mod tests { #[test] fn test_simple() { - let typing_speed_ms = Duration::from_millis(300); + let typing_speed_ms = Duration::from_millis(500); // To detect excessive backspace const LIMIT: &str = "bbb"; diff --git a/clafrica/src/processor.rs b/clafrica/src/processor.rs index 2f8eab1..bbc90a9 100644 --- a/clafrica/src/processor.rs +++ b/clafrica/src/processor.rs @@ -26,8 +26,9 @@ impl Processor { match event.event_type { EventType::KeyPress(E_Key::Backspace) => { + self.pause(); + if let Some(out) = self.cursor.undo() { - self.pause(); self.keyboard.key_up(Key::Backspace); (1..out.chars().count()).for_each(|_| self.keyboard.key_click(Key::Backspace)); @@ -41,11 +42,11 @@ impl Processor { self.keyboard.key_sequence(&_in); } - self.resume(); committed = true; } changed = true; + self.resume(); } EventType::KeyPress( E_Key::Unknown(_) | E_Key::ShiftLeft | E_Key::ShiftRight | E_Key::CapsLock, @@ -57,11 +58,10 @@ impl Processor { changed = true; } EventType::KeyPress(_) => { + self.pause(); let character = character.unwrap(); if let Some(_in) = self.cursor.hit(character) { - self.pause(); - let mut prev_cursor = self.cursor.clone(); prev_cursor.undo(); self.keyboard.key_click(Key::Backspace); @@ -78,11 +78,11 @@ impl Processor { } self.keyboard.key_sequence(&_in); - self.resume(); committed = true; }; changed = true; + self.resume(); } _ => (), }; @@ -95,9 +95,9 @@ impl Processor { (0..code.len() - remaining_code.len()) .for_each(|_| self.keyboard.key_click(Key::Backspace)); self.keyboard.key_sequence(text); - self.resume(); // We clear the buffer self.cursor.clear(); + self.resume(); } fn pause(&mut self) {