fix: fix caret error on incorrect final word (@Positiveoo1)#8191
Open
Positiveoo1 wants to merge 1 commit into
Open
fix: fix caret error on incorrect final word (@Positiveoo1)#8191Positiveoo1 wants to merge 1 commit into
Positiveoo1 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a frontend caret crash that can occur when moving past an incorrectly-typed final word by (a) ensuring the word’s <letter> DOM is updated on incorrect word transitions and (b) making caret positioning more defensive when expected <letter> nodes are missing.
Changes:
- Update
beforeTestWordChangeto callupdateWordLetterswhencorrect === false. - Adjust caret target resolution to fall back when the requested letter index isn’t present (instead of throwing).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/ts/test/test-ui.ts | Forces word-letter DOM refresh when leaving an incorrect word to keep caret/word rendering consistent. |
| frontend/src/ts/elements/caret.ts | Avoids throwing when no target <letter> exists; adds fallback positioning logic. |
Comment on lines
+398
to
405
| let letter = letters?.[options.letterIndex] ?? letters?.at(-1); | ||
| if (letter === undefined) { | ||
| return { | ||
| left: options.word.getOffsetLeft(), | ||
| top: options.word.getOffsetTop(), | ||
| width: getTotalInlineMargin(options.word.native), | ||
| }; | ||
| } |
Miodec
requested changes
Jul 3, 2026
Comment on lines
+398
to
+404
| let letter = letters?.[options.letterIndex] ?? letters?.at(-1); | ||
| if (letter === undefined) { | ||
| return { | ||
| left: options.word.getOffsetLeft(), | ||
| top: options.word.getOffsetTop(), | ||
| width: getTotalInlineMargin(options.word.native), | ||
| }; |
Member
There was a problem hiding this comment.
I think i would change this to something like
const letters = options.word?.qsa("letter");
if (letters.length === 0) {
throw new Error(
"Caret getTargetPositionAndWidth: no letters found in word",
);
}
const letter = letters[options.letterIndex] ?? letters[letters.length - 1];
if (!letter) {
throw new Error(
`Caret getTargetPositionAndWidth: letter not found for index ${options.letterIndex}`,
);
}
if (caretDebug) {| if ( | ||
| (Config.stopOnError === "letter" && (correct || correct === null)) || | ||
| nospaceEnabled || | ||
| correct === false || |
Member
There was a problem hiding this comment.
And revert this. This code will be changed soon anyway.
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.
Fixes #8180
Summary
Testing
a aa, space,f, spaceCaret getTargetPositionAndWidth: no letters found in word