Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed May 12, 2023
1 parent 2460d68 commit fb3ba71
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), io::Error>
for event in rx.iter() {
let character = event.name.and_then(|s| s.chars().next());
let is_valid = character
.map(|c| c.is_ascii() && !c.is_whitespace())
.map(|c| c.is_alphanumeric() || c.is_ascii_punctuation())
.unwrap_or_default();

match event.event_type {
EventType::KeyPress(E_Key::Backspace) => {
if let Some(out) = cursor.undo() {
keyboard.key_down(Key::Pause);
rdev::simulate(&EventType::KeyPress(E_Key::Pause));
keyboard.key_up(Key::Backspace);

let i = out.chars().count();
Expand All @@ -71,7 +71,7 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), io::Error>
keyboard.key_sequence(&prev_out);
}

keyboard.key_up(Key::Pause);
rdev::simulate(&EventType::KeyRelease(E_Key::Pause));

// Clear the remaining code
while let (None, _i @ 1.., ..) = cursor.state() {
Expand All @@ -86,6 +86,7 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), io::Error>
}
EventType::ButtonPress(_) | EventType::KeyPress(_) if !is_valid => {
cursor.clear();
frontend.update_text(cursor.to_path());
}
EventType::KeyPress(_) => {
let character = character.unwrap();
Expand All @@ -94,13 +95,13 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), io::Error>
let out = cursor.hit(character);

if let Some(out) = out {
keyboard.key_down(Key::Pause);
rdev::simulate(&EventType::KeyPress(E_Key::Pause));

let i = prev_out.map(|s| s.chars().count()).unwrap_or(prev_code_len) + 1;
(0..i).for_each(|_| keyboard.key_click(Key::Backspace));
keyboard.key_sequence(&out);

keyboard.key_up(Key::Pause);
rdev::simulate(&EventType::KeyRelease(E_Key::Pause));
};

frontend.update_text(cursor.to_path());
Expand Down

0 comments on commit fb3ba71

Please sign in to comment.