Repository navigation
annotations: open the note beside its marker when it covers only the empty space of a longer line next to it - #12
Merged
Merged
Conversation
…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>
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.
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()becomescoversText()and reuses theintersects()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
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) andpnpm docs:buildpass with no warnings.🤖 Generated with Claude Code