Skip to content

fix: fix caret error on incorrect final word (@Positiveoo1)#8191

Merged
Miodec merged 2 commits into
monkeytypegame:masterfrom
Positiveoo1:fix/caret-incorrect-final-word
Jul 4, 2026
Merged

fix: fix caret error on incorrect final word (@Positiveoo1)#8191
Miodec merged 2 commits into
monkeytypegame:masterfrom
Positiveoo1:fix/caret-incorrect-final-word

Conversation

@Positiveoo1

@Positiveoo1 Positiveoo1 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #8180

Summary

  • Render incorrect committed words before word change UI updates
  • Prevent caret positioning from throwing when target word has no rendered letters yet

Testing

  • Custom text: a a
  • Typed a, space, f, space
  • Confirmed console no longer throws Caret getTargetPositionAndWidth: no letters found in word

Copilot AI review requested due to automatic review settings July 3, 2026 18:07
@monkeytypegeorge monkeytypegeorge added the frontend User interface or web stuff label Jul 3, 2026
@github-actions github-actions Bot added the waiting for review Pull requests that require a review before continuing label Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 beforeTestWordChange to call updateWordLetters when correct === 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 thread frontend/src/ts/elements/caret.ts Outdated
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),
};
}
@Positiveoo1 Positiveoo1 changed the title fix caret error on incorrect final word fix: fix caret error on incorrect final word Jul 3, 2026
@Positiveoo1 Positiveoo1 changed the title fix: fix caret error on incorrect final word fix(test): fix caret error on incorrect final word (@Positiveoo1) Jul 3, 2026
@Positiveoo1 Positiveoo1 changed the title fix(test): fix caret error on incorrect final word (@Positiveoo1) fix: fix caret error on incorrect final word (@Positiveoo1) Jul 3, 2026
Comment thread frontend/src/ts/elements/caret.ts Outdated
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),
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks. Reverted the test-ui change and changed caret lookup to fall back only when the requested index is missing.

Comment thread frontend/src/ts/test/test-ui.ts Outdated
if (
(Config.stopOnError === "letter" && (correct || correct === null)) ||
nospaceEnabled ||
correct === false ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And revert this. This code will be changed soon anyway.

@github-actions github-actions Bot added waiting for update Pull requests or issues that require changes/comments before continuing and removed waiting for review Pull requests that require a review before continuing labels Jul 3, 2026
@github-actions github-actions Bot removed the waiting for update Pull requests or issues that require changes/comments before continuing label Jul 4, 2026
@Positiveoo1 Positiveoo1 requested a review from Miodec July 4, 2026 06:43
@github-actions github-actions Bot added the waiting for review Pull requests that require a review before continuing label Jul 4, 2026
@Miodec Miodec merged commit 00fbfb0 into monkeytypegame:master Jul 4, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend User interface or web stuff waiting for review Pull requests that require a review before continuing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no letters found in word error when committing an incorrect last word with a space

4 participants