Skip to content

Commit

Permalink
fix(clafrica): clear the buffer after each new word
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed May 8, 2023
1 parent 00cb399 commit b030b38
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub fn run(config: Config) -> Result<(), io::Error> {

for event in rx.iter() {
let character = event.name.and_then(|s| s.chars().next());
let is_ascii = character.map(|c| c.is_ascii()).unwrap_or_default();
let is_valid = character
.map(|c| c.is_ascii() && !c.is_whitespace())
.unwrap_or_default();

match event.event_type {
EventType::KeyPress(E_Key::Backspace) => {
Expand All @@ -76,7 +78,7 @@ pub fn run(config: Config) -> Result<(), io::Error> {
EventType::KeyPress(E_Key::Unknown(_) | E_Key::ShiftLeft | E_Key::ShiftRight) => {
println!("[ignore] {:?}", event.event_type)
}
EventType::ButtonPress(_) | EventType::KeyPress(_) if !is_ascii => {
EventType::ButtonPress(_) | EventType::KeyPress(_) if !is_valid => {
cursor.clear();
println!("Buffer cleared");
}
Expand Down

0 comments on commit b030b38

Please sign in to comment.