Repository navigation
fix(core): read a page anchor's caret inside its line box - #803
Conversation
`getFirstNodeInBox` refines a page's anchor with a caret at the start of the first line box on the page: its right edge for horizontal text written right to left. For a line box under two pixels wide, `Math.floor(right) - 1` fell left of the box, so the caret could name a character outside it. The point is now held at or right of the box's left edge. Unit tests stub `caretPositionFromPoint` and check the point the lookup asks for: left to right, right to left, and a line box 1.2 px wide. The right-to-left test fails with the caret at the left edge, and the narrow box test fails on the point before this change.
…s right edge `Math.ceil(right) - 1` mirrors `Math.ceil(left)`: it lands inside every line box that spans a whole pixel, narrow ones included, so the clamp goes. The comments say what the point is and what the test stub does.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25f66dc678
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| expect(points).toEqual([{ x: 499, y: 10 }]) | ||
| }) | ||
|
|
||
| it("reads the caret inside a line written right to left that is under two pixels wide", () => { |
There was a problem hiding this comment.
Cover the narrow RTL anchor in a real browser
For the narrow right-to-left line that motivates this change, this happy-dom test fabricates both the line box and the caret response, so it only verifies the arithmetic and cannot show that browser hit-testing produces an anchor inside the line. I checked apps/tests/tests/navigation/pages/pages.spec.ts; its RTL scenarios do not create a sub-two-pixel line or assert the resulting anchor offset. Add a Playwright regression using real narrow RTL text, since layout-dependent core behavior is not covered until it has a browser spec.
AGENTS.md reference: packages/core/AGENTS.md:L11-L16
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This PR changes only which point prose picks inside a line box the browser has already measured. The unit test checks that choice at the box's edges, and it fails on the formula before this PR.
A real right-to-left line box under two pixels wide needs crafted content, such as a hair space at the start of a page. A browser spec for it would mostly test the browser's own hit-testing, which this PR does not change. The right-to-left first-node specs in tests/navigation/pages already run this code with real text, and they pass.
I left the browser spec out and asked the maintainer to decide.
Generated by Claude Code
…t scale The restoration spec of #798 shrank the font in ten steps and needed one step that moved the first node shown to another page while the chapter kept its number of pages. Which step does depends on the browser's fonts: on develop, none did on Firefox for the vertical-writing book, nor on WebKit and Mobile Safari for the right-to-left book. The spec now puts a spacer before the chapter's text and one after it, two pages long. Moving the space from the one after to the one before moves the text exactly two pages on, and the chapter keeps its number of pages in every browser. The spec checks both, then that the reader shows the page two pages on, with the node on screen. It passes on Chromium, Firefox, WebKit, Mobile Safari and Mobile Chrome. With the restoration from before #798, it fails for the right-to-left and vertical-writing books in every window: the reader stays on its page.
Why
The anchor of a page in a right-to-left book can name a character outside the page's first line box. Prose reads the anchor's caret point one pixel inside the right edge of that line box. For a line box under two pixels wide, the caret point fell left of the line box. Follow-up of #798.
The restoration spec that #798 added also fails on
developon Firefox, WebKit and Mobile Safari: it depended on the browser's fonts.Math.ceil(right) - 1, which is inside every line box that holds a whole pixel. The restoration spec moves the text with spacers instead of the font scale.Changes
Public API
None. The change is in an internal helper of
@prose-reader/core, and in the test app.Validation
Details
What the caret tests show
develop: the caret point is at x = 100, left of a line box from 100.5 to 101.7.develop. It fails if the caret point goes back to the left edge of the line box.The restoration spec of #798
The spec shrank the font in ten steps, and needed one step that moved the first node shown to another page while the chapter kept its number of pages. Which step does depends on the browser's fonts. On
develop, no step did on Firefox for the vertical-writing book, nor on WebKit and Mobile Safari for the right-to-left book.The spec now puts a spacer before the chapter's text and one after it, two pages long. Moving the space from one spacer to the other moves the text exactly two pages on, and the chapter keeps its number of pages. The spec checks both, then that the node is on screen.
Not covered
A vertical line box of text with
direction: rtlstarts at its bottom. Prose reads its caret point at the top, and no test covers the vertical case. It is rare: Japanese vertical text keepsdirection: ltr.🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage