fix(editor): align highlight overlay with text (was ~2px off)#1
Merged
Conversation
…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>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
wsc | 6d01bf5 | Jul 14 2026, 10:37 AM |
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.
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-overlayapplies its own CSS padding to inset the highlights wrapper, butgetPositionInEditor()inApp.sveltealso re-added the textarea's padding, plus acharacterOffset = 1.0(one char-width) fudge to try to compensate. On top of that:10px) didn't match the textarea's (12px).padding-top: 1pxwas 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 to12pxso it matches the textarea exactly.src/lib/App.svelte—getPositionInEditor()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
npm run check→ 0 errors.🤖 Generated with Claude Code