Skip to content

Keep text in place when a wrong key lands on a space - #9

Merged
Byntham merged 1 commit into
mainfrom
t3/prevent-text-shift-on-typo
Nov 5, 2026
Merged

Byntham merged 1 commit into
mainfrom
t3/prevent-text-shift-on-typo

Conversation

@Byntham

@Byntham Byntham commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Problem

A wrong key where a space belongs shows a red dot. The dot replaced the space character, and on a Mac the system font draws "·" at a different width than " ". So every typo on a space nudged the rest of the line sideways. The text should never move while you type.

Fix

The span now keeps the real space, so its width and line breaks match a correct keystroke. The dot is drawn on top of the space as an absolutely positioned overlay that takes no layout room.

Proof

New check in tests/play.mjs. It forces Liberation Sans, where a space is 27.8 and a dot is 33.3 at 100px, the same kind of gap the Mac font has. It then compares the left edge of the untyped text after a correct space and after a wrong key on that space.

  • Before the fix: FAIL a wrong key on a space does not move the text after it (541.484375 vs 542.59375)
  • After the fix: ok ... (541.484375 vs 541.484375)

The dot looks the same as before (Inter, 3x zoom):

Before After
before after

With Liberation Sans, the dot sits centered in the narrower space:

liberation

npm run lint, npm run typecheck, npm run test:unit (28 passed), and node tests/play.mjs (38 ok) all pass. I could not test on a Mac with the real system font. The Liberation Sans check stands in for it.

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

The red dot for a missed space replaced the space glyph. In fonts where the dot is wider or narrower than a space (the Mac system font), the rest of the line shifted. The span now keeps the real space and draws the dot on top of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Byntham
Byntham merged commit ed222a1 into main Nov 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant