Skip to content

Commit

Permalink
chore(clafrica): update
Browse files Browse the repository at this point in the history
- chore: We prefer stop listening before any operation
- test: We don't need to wait before release the key
  • Loading branch information
pythonbrad committed Sep 16, 2023
1 parent 23c1292 commit c9a8934
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ mod tests {
$(
thread::sleep($delay);
rdev::simulate(&KeyPress($key)).unwrap();
thread::sleep($delay);
rdev::simulate(&KeyRelease($key)).unwrap();
)*
);
Expand Down Expand Up @@ -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";
Expand Down
12 changes: 6 additions & 6 deletions clafrica/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -78,11 +78,11 @@ impl Processor {
}

self.keyboard.key_sequence(&_in);
self.resume();
committed = true;
};

changed = true;
self.resume();
}
_ => (),
};
Expand All @@ -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) {
Expand Down

0 comments on commit c9a8934

Please sign in to comment.