Skip to content

fix(core): read a page anchor's caret inside its line box - #803

Merged
mbret merged 3 commits into
developfrom
claude/wizardly-wozniak-yp4d1f
Nov 16, 2026
Merged

mbret merged 3 commits into
developfrom
claude/wizardly-wozniak-yp4d1f

Conversation

@mbret

@mbret mbret commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

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 develop on Firefox, WebKit and Mobile Safari: it depended on the browser's fonts.

  • Change: prose reads the caret point at 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

  • 🐛 The caret point stays inside a narrow line box of right-to-left text.
  • ✅ Unit tests check the caret point for left-to-right text, right-to-left text, and a line box 1.2 pixels wide.
  • 💚 The restoration spec of fix(core)!: find a node's page in RTL and vertical books #798 moves the text by exactly two pages, so it no longer depends on the browser's fonts.

Public API

None. The change is in an internal helper of @prose-reader/core, and in the test app.

Validation

  • Ran the checks this change touches
  • Added or updated tests
  • Checked that the documentation still holds: the docs do not cover this helper

Details

What the caret tests show

  • The narrow line box test fails on develop: the caret point is at x = 100, left of a line box from 100.5 to 101.7.
  • The right-to-left test passes on develop. It fails if the caret point goes back to the left edge of the line box.
  • The change is arithmetic on a line box the browser already measured, so the unit tests cover it.

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: rtl starts at its bottom. Prose reads its caret point at the top, and no test covers the vertical case. It is rare: Japanese vertical text keeps direction: ltr.

🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage

`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.
@mbret mbret self-assigned this Nov 15, 2026
@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
prose-reader-docs Skipped Skipped Nov 15, 2026 7:58pm UTC
prose-reader-front Skipped Skipped Nov 15, 2026 7:58pm UTC

@mbret
mbret marked this pull request as ready for review November 15, 2026 19:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T19:24:36.168125Z 25f66dc Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@vercel
vercel Bot temporarily deployed to Preview – prose-reader-docs November 15, 2026 19:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – prose-reader-front November 15, 2026 19:58 Inactive
@mbret
mbret merged commit 64ce5a5 into develop Nov 16, 2026
17 checks passed
@mbret
mbret deleted the claude/wizardly-wozniak-yp4d1f branch November 16, 2026 12:16

This branch was previously deployed

2 inactive deployments
Preview – prose-reader-front — 70b1f827 Deployed Nov 15, 2026 by vercel[bot]
Preview – prose-reader-docs — 70b1f827 Deployed Nov 15, 2026 by vercel[bot]
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.

2 participants