Skip to content

annotations: open the note beside its marker when it covers only the empty space of a longer line next to it - #12

Merged
ewels merged 1 commit into
mainfrom
annotations-fits-beside
Oct 5, 2026
Merged

ewels merged 1 commit into
mainfrom
annotations-fits-beside

Conversation

@ewels

@ewels ewels commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Closes #9

fitsBeside() rejected the beside position when any line row overlapped the note box vertically and its text reached past the box's left edge. The note box is taller than a row, so a longer line above or below the marker always failed the check, even though the note covered only the empty space under or over its text.

fitsBeside() now tests the note against the glyph boxes of each text node (Range.getClientRects()), in place of whole rows. textEnd() becomes coversText() and reuses the intersects() helper.

A glyph box alone is not enough. In Chromium, with the docs site's font, a 14px glyph box is 16px tall in a 24.5px row, and a one-line note beside its marker still overlaps the glyph boxes of the next rows by about 2px. So the check ignores the top and bottom quarter of each glyph box, where the ink of most glyphs does not reach. With the issue's example the note now opens beside line 2, and a note that covers real text still opens below.

Tests

  • New Playwright test in docs/e2e/annotations.test.ts: it makes the line above the first annotated line on the annotations page longer than the marker's position, and checks that the note still opens beside the marker. The old row check fails this test.
  • pnpm lint, pnpm test (414 Vitest tests and the script tests) and pnpm docs:build pass with no warnings.
  • The full Playwright suite passes: 731 passed, 304 skipped.

🤖 Generated with Claude Code

…empty space of a longer line next to it

fitsBeside() tested the note against whole line rows, so a longer line above or below rejected the beside position even though the note covered none of its text. It now tests the note against the glyph boxes of each text node, minus their top and bottom quarter, which the note may overlap.

Closes #9

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ewels
ewels merged commit 46878fc into main Oct 5, 2026
3 checks passed
@ewels
ewels deleted the annotations-fits-beside branch October 5, 2026 11:12
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.

Annotations: note opens below the marker when an adjacent line is longer, though it fits beside

1 participant