A leaderboard is only worth climbing if the numbers on it mean the same thing for everyone. Two small input rules protect that: holding a key does not type, and words you finished correctly stay finished.
Try both rules
Type the sentence. Make a mistake, then try to backspace past it.
Type the sentence. Hold a letter key down: nothing repeats. Finish a word correctly with its space and it gets underlined; backspace stops at the underline. Make a mistake and the lock stops advancing, so you can still go back and fix it.
Held keys do not count
When you hold a key, the operating system repeats it 30 or more times a second. Those repeats looked like extremely fast typing: raw WPM shot up, and holding the space bar could push net WPM higher by skipping through words.
onKeyDown={(e) => {
// Hold keys don't type, backspace hold still deletes.
if (e.repeat && e.key !== "Backspace") {
e.preventDefault();
return;
}
// ...
}}
The browser marks every auto-repeated keydown with repeat: true. Preventing its default stops the character from reaching the input, so handleChange never sees it. Backspace is the exception because holding it to clear a mistake is ordinary typing. The rule applies to every test, signed in or not.
Word lock
Pick a step, or use the arrows, to walk through the diagram.
The check before it is one comparison: if the new input is shorter than the old one and shorter than the lock, the edit is rejected and the input is put back:
if (newInput.length < userInputRef.current.length) {
if (newInput.length < lockedIndexRef.current) {
e.target.value = userInputRef.current;
return;
}
}
The lock is contiguous from the start of the passage. A mistake in word three keeps words four, five and six unlocked even after you type them correctly, because the lock cannot jump over the mistake. To fix it you backspace through those words (they are not locked), correct word three, and retype; each word locks again as you finish it.
Ctrl+Backspace (delete a whole word) goes through the same check: it is accepted only if what remains is still at or past the lock.
Why lock words at all
Without the lock, accuracy could be rewritten after the fact. Accuracy is computed against the final input, so someone could type a whole passage carelessly, go back, fix every error, and finish with 100%. The time spent fixing would count, but the errors would vanish from the score.
The lock keeps corrections local: you can fix the word you are on, not the paragraph behind you.
When the lock resets
lockedIndexRef goes back to 0 on every restart, mode or option change, text option change, and when a multiplayer round gives the engine new text. A new passage with an old lock would block backspace in places that were never typed.
What this does not do
These are input rules, not proof that a person typed a score. A modified client can skip them. Server-side result checks are the separate layer that decides what gets saved, and keystroke telemetry is what looks at typing rhythm.
Try it yourself
Open the typing test and see the change for yourself.