Skip to content

fix(editor): align highlight overlay with text (was ~2px off)#1

Merged
rush-skills merged 1 commit into
masterfrom
fix/editor-highlight-alignment
Jul 14, 2026
Merged

fix(editor): align highlight overlay with text (was ~2px off)#1
rush-skills merged 1 commit into
masterfrom
fix/editor-highlight-alignment

Conversation

@rush-skills

Copy link
Copy Markdown
Member

What

The text-highlight boxes in the web editor were rendering a few pixels off from the underlying text — ~2px too far right and 1px too far down.

Root cause

Padding was being counted twice. The .highlight-overlay applies its own CSS padding to inset the highlights wrapper, but getPositionInEditor() in App.svelte also re-added the textarea's padding, plus a characterOffset = 1.0 (one char-width) fudge to try to compensate. On top of that:

  • The overlay's horizontal padding (10px) didn't match the textarea's (12px).
  • The vertical padding-top: 1px was double-counted.

Because the horizontal fudge was 10 − charWidth, the drift scaled with font size rather than staying fixed.

Fix

  • src/styles/main.scss — set the overlay's horizontal padding to 12px so it matches the textarea exactly.
  • src/lib/App.sveltegetPositionInEditor() now returns pure content-box coordinates ((col-1)*charWidth, (line-1)*lineHeight); the shared overlay padding does the aligning. This also fixes the "Go to" jump highlight and duplicate-word boxes, which use the same function.

Verification

  • Measured live in-browser after the fix: vertical offset exactly 0, horizontal sub-pixel.
  • Visual zoom confirms boxes hug their words.
  • npm run check → 0 errors.

🤖 Generated with Claude Code

…own)

The highlight boxes were offset because padding was counted twice: the
.highlight-overlay applies its own CSS padding to inset the highlights
wrapper, but getPositionInEditor() also re-added the textarea's padding
plus a characterOffset (one char-width) fudge. The overlay padding (10px)
also didn't match the textarea's (12px), and padding-top was double-counted.

Net drift, measured live: ~2px too far right (10 - charWidth, font-size
dependent) and 1px too far down.

Fix: match the overlay's horizontal padding to the textarea (12px) and
position highlights in pure content-box coordinates — the shared padding
does the aligning. Also fixes the "Go to" jump highlight and duplicate-word
boxes, which share getPositionInEditor().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
wsc 6d01bf5 Jul 14 2026, 10:37 AM

@rush-skills
rush-skills merged commit 605d8d7 into master Jul 14, 2026
6 checks 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