Skip to content

Commit 5110a64

Browse files
committed
fix: record keystroke before typing core input processing
- Move record_keystroke() calls to execute before typing core processes input - Ensures ScoringEngine receives correct position before it advances - Previously scoring was broken because position had already advanced - Fixes WPM, CPM, and accuracy calculations showing 0 values
1 parent de29b0a commit 5110a64

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/game/screens/typing_screen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,20 @@ impl TypingScreen {
212212
}
213213

214214
fn handle_tab_key(&mut self) -> Result<SessionState> {
215-
let result = self.typing_core.process_tab_input();
216215
self.scoring_engine.record_keystroke('\t', self.typing_core.current_position_to_type());
216+
let result = self.typing_core.process_tab_input();
217217
self.handle_input_result(result)
218218
}
219219

220220
fn handle_enter_key(&mut self) -> Result<SessionState> {
221-
let result = self.typing_core.process_enter_input();
222221
self.scoring_engine.record_keystroke('\n', self.typing_core.current_position_to_type());
222+
let result = self.typing_core.process_enter_input();
223223
self.handle_input_result(result)
224224
}
225225

226226
fn handle_character_input(&mut self, ch: char) -> Result<SessionState> {
227-
let result = self.typing_core.process_character_input(ch);
228227
self.scoring_engine.record_keystroke(ch, self.typing_core.current_position_to_type());
228+
let result = self.typing_core.process_character_input(ch);
229229
self.handle_input_result(result)
230230
}
231231

0 commit comments

Comments
 (0)