Skip to content

Commit

Permalink
fix(test): allow typing words beginning with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Apr 14, 2022
1 parent d790a51 commit f66f647
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/test/mod.rs
Expand Up @@ -56,22 +56,21 @@ impl Test {
let word = &mut self.words[self.current_word];
match key.code {
KeyCode::Char(' ') | KeyCode::Enter => {
if !word.progress.is_empty() || word.text.is_empty() {
if word.text.chars().nth(word.progress.len()) == Some(' ') {
word.progress.push(' ');
word.events.push(TestEvent {
time: Instant::now(),
correct: Some(true),
key,
})
} else {
word.events.push(TestEvent {
time: Instant::now(),
correct: Some(word.text == word.progress),
key,
});
self.next_word();
}

if word.text.chars().nth(word.progress.len()) == Some(' ') {
word.progress.push(' ');
word.events.push(TestEvent {
time: Instant::now(),
correct: Some(true),
key,
})
} else if !word.progress.is_empty() || word.text.is_empty() {
word.events.push(TestEvent {
time: Instant::now(),
correct: Some(word.text == word.progress),
key,
});
self.next_word();
}
}
KeyCode::Backspace => {
Expand Down

0 comments on commit f66f647

Please sign in to comment.