refactor(generator): include commit spaces in generated words (@miodec, @Leonabcd123)#8157
Draft
Miodec wants to merge 46 commits into
Draft
refactor(generator): include commit spaces in generated words (@miodec, @Leonabcd123)#8157Miodec wants to merge 46 commits into
Miodec wants to merge 46 commits into
Conversation
Miodec
commented
Jun 24, 2026
Words now carry their commit separator as a trailing space emitted by the generator (getNextWord) instead of being added retroactively to the previous word in Words.push. The old retroactive model assumed the next word was always generated before the current one was committed, which is false for plus_zero (toPush:1, zero lookahead): the current word was read bare during live validation, breaking commit, stop-on-error, expert, and quick-end. - strip prev words inside getNextWord so trailing separators don't leak into dedup/punctuation/capitalization feedback - guard the separator append for nospace mode and newline-terminated words - strip the trailing separator from the final word once generation is complete, covering the bulk, section, and lazy addWord paths (final word stays bare) - restore the expert-mode guard so a leading separator (empty input) never fails - move areAllTestWordsGenerated -> areAllWordsGenerated in words-generator Update test-words/validation/fail-or-finish specs to the new contracts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors test word generation + input/navigation to treat the commit/separator (space/newline, plus nospace “implicit commit”) as part of the target word, and updates stats/replay/export + tests accordingly.
Changes:
- Generator now appends a trailing separator and words model stores it as
textWithCommit/commit. - Input pipeline updated to detect “commit characters” and decide navigation via
shouldGoToNextWord. - Event log/replay/export paths switched to use
textWithCommit; tests updated/added.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/ts/test/words-generator.ts | Appends trailing separator on generated words; adds areAllWordsGenerated(). |
| frontend/src/ts/test/test-words.ts | Splits trailing separator into commit + textWithCommit; adds last-word commit stripping helper. |
| frontend/src/ts/test/test-ui.ts | Adjusts word HTML handling/comments; changes input UI update flow (currently includes debug spam). |
| frontend/src/ts/test/test-logic.ts | Uses generator-level areAllWordsGenerated; strips last-word separator when generation complete. |
| frontend/src/ts/test/replay-ui.ts | Replays with textWithCommit. |
| frontend/src/ts/test/pace-caret.ts | Updates pace-caret indexing/correction math for new word representation. |
| frontend/src/ts/test/events/stats.ts | Simplifies target-word lookup; adjusts char counting + missed-words logic. |
| frontend/src/ts/test/events/helpers.ts | Stops trimming end on last-word incorrect commit case. |
| frontend/src/ts/test/events/data.ts | Stops trimming end in getInputForWord; event log targetWords now textWithCommit. |
| frontend/src/ts/input/listeners/input.ts | Switches completion check to areAllWordsGenerated. |
| frontend/src/ts/input/helpers/word-navigation.ts | Simplifies previous-word nav signature; handles trailing separator when restoring input. |
| frontend/src/ts/input/helpers/validation.ts | Replaces old “space insertion” logic with shouldGoToNextWord. |
| frontend/src/ts/input/helpers/util.ts | New helper to detect “commit character” (space/newline/nospace completion). |
| frontend/src/ts/input/helpers/fail-or-finish.ts | Updates difficulty/finish helpers to use commit-character + navigation semantics. |
| frontend/src/ts/input/handlers/insert-text.ts | Refactors commit/navigation logic around commit-characters + separator-in-target-word model. |
| frontend/src/ts/input/handlers/delete.ts | Updates previous-word navigation call sites. |
| frontend/src/ts/input/handlers/before-insert-text.ts | Updates over-limit + line-wrap prevention using commit-character logic. |
| frontend/src/ts/elements/caret.ts | Import ordering only. |
| frontend/src/ts/commandline/lists/result-screen.ts | Copies typed words using textWithCommit and joins without adding spaces. |
| frontend/tests/test/test-words.spec.ts | New unit tests for separator splitting + stripping behavior. |
| frontend/tests/test/events/stats.spec.ts | Updates stats target-word tests for simplified behavior. |
| frontend/tests/input/helpers/validation.spec.ts | Updates tests for new shouldGoToNextWord contract + separator correctness. |
| frontend/tests/input/helpers/fail-or-finish.spec.ts | Updates difficulty/finish tests for commit-character based logic. |
Comment on lines
240
to
242
| const commitCorrect = noSpaceForce | ||
| ? testInput + data === currentWord | ||
| : correct; |
Comment on lines
+76
to
+87
| removeCommitCharacterFromLastWord(): void { | ||
| if (this.length === 0) return; | ||
| const lastWord = this.list[this.length - 1]; | ||
| if (lastWord === undefined) return; | ||
| if ( | ||
| lastWord.textWithCommit.endsWith(" ") || | ||
| lastWord.textWithCommit.endsWith("\n") | ||
| ) { | ||
| lastWord.textWithCommit = lastWord.textWithCommit.slice(0, -1); | ||
| lastWord.display = lastWord.textWithCommit; | ||
| } | ||
| } |
Comment on lines
109
to
113
| const word = getInputForWord(TestState.activeWordIndex); | ||
| if (nospaceEnabled) { | ||
| setInputElementValue(word.slice(0, -1)); | ||
| } else if (word.endsWith("\n")) { | ||
| } else if (word.endsWith("\n") || word.endsWith(" ")) { | ||
| setInputElementValue(word.slice(0, -1)); |
| const { data, inputValue, targetWord } = options; | ||
| if (!isSpace(data)) { | ||
| return null; | ||
| const correct = inputValue + data === targetWord; |
Comment on lines
+242
to
+246
| if (goingToNextWord) { | ||
| const result = await goToNextWord({ | ||
| correctInsert: commitCorrect, | ||
| correctInsert: testInput + data === currentWord, | ||
| isCompositionEnding: isCompositionEnding === true, | ||
| zenNewline: charIsNewline && Config.mode === "zen", | ||
| zenNewline: data === "\n" && Config.mode === "zen", |
Comment on lines
+873
to
+874
| const bareWord = word; | ||
| missedWords[bareWord] = (missedWords[bareWord] ?? 0) + 1; |
| return eventLog.context.targetWords[wordIndex]; | ||
| } | ||
|
|
||
| function computeBurst(events: TestEventNoMs[], now?: number): number { |
Comment on lines
154
to
160
| // is char correct | ||
| const charCorrect = isCharCorrect({ | ||
| const correct = isCharCorrect({ | ||
| data, | ||
| inputValue: testInput, | ||
| targetWord: currentWord, | ||
| correctShiftUsed, | ||
| }); |
Comment on lines
381
to
384
| // the stored trailing separator space is not rendered as a letter | ||
| const chars = Strings.splitIntoCharacters(word); | ||
| for (const char of chars) { | ||
| if (funbox) { |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
frontend/src/ts/test/practise-words.ts:70
- If getMissedWords is keyed by bare words (no trailing commit separator), this lookup should also use the bare word. Using textWithCommit here will fail to match and can also inject trailing separators into the generated practice text.
const missedWord = TestWords.words.get(i)?.textWithCommit;
if (missedWord === undefined) continue; // won't happen, but ts complains
const missedWordCount = missedWords[missedWord];
Comment on lines
+50
to
+56
| //strict space | ||
| if ( | ||
| inputValue.length === 0 && | ||
| (Config.strictSpace || Config.difficulty !== "normal") | ||
| ) { | ||
| return false; | ||
| } |
| @@ -0,0 +1,26 @@ | |||
| import { isFunboxActiveWithProperty } from "../../test/funbox/active"; | |||
Comment on lines
+248
to
+254
| Space/word-navigation variables: | ||
| - charIsSpace / charIsNewline: was the input a space or a newline? | ||
| - goingToNextWord: should this input commit the current word and move on? | ||
| The separator is part of the target word (stored as a trailing space), so a | ||
| space/newline matches it positionally; navigation can still be blocked by | ||
| stop-on-error, strict space, or opposite shift (removeLastChar). | ||
| - increasedWordIndex: only set because on the last word we don't move on. |
Comment on lines
1786
to
1788
| //nospace cant be handled here becauseword index | ||
| // is already increased at this point | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reworks the generation to include commit/separation character in the target word.