rangeFromLocator can return a collapsed range when text.highlight spans a paragraph boundary

Open
#812 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #813 by @phikaczu — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
html, swift
Domain
mobile-dev

Research direction

Start at rangeFromLocator and trace how it turns the Locator's text context into a range, especially when the highlight spans a paragraph boundary. Reproduce with the two-paragraph HTML fixture described in the issue, including the self-closing indexterm anchors. Done means the range is not collapsed and confirming the selection produces a visible highlight.

Written by the indexing model from the issue text.

Description

Describe the bug

When highlighting text in certain paragraphs of a commercial EPUB, the highlight commit path completes but no highlight renders visibly. The same gesture in adjacent paragraphs renders correctly. Visually, the failing paragraphs look like ordinary text paragraphs.

Expected: a visible highlight, matching the behavior in other paragraphs.
Observed: no visible highlight is rendered.

How to reproduce

The sample EPUB attached in this thread reproduces it: sample.epub.zip.

  1. Open the sample EPUB in a Readium-based reader.
  2. Long-press-drag a selection across the boundary between the two paragraphs.
  3. Confirm the highlight.
  4. Observe: no visible highlight is rendered.

The minimal failing structure is a two-paragraph fixture where the second paragraph opens with self-closing <a data-type="indexterm"/> anchors and repeats a noun phrase from the end of the first paragraph:

<p id="p-source">…"Uniform initialization" is an idea. "Braced initialization" is a syntactic construct.</p>
<p id="p-target"><a contenteditable="false" data-type="indexterm"></a><a contenteditable="false" data-type="indexterm"></a><a contenteditable="false" data-type="indexterm"></a>Braced initialization lets you express the formerly inexpressible.</p>

The selection that triggers the bug spans the paragraph boundary, producing this text context in the Locator:

locator.text = {
  before:    "…'Braced initialization' ",
  highlight: "is a syntactic construct.\nBraced initialization lets you express",
  after:     " the formerly inexpressible."
};

The book where this was originally encountered is copyrighted (Effective Modern C++, O'Reilly) and cannot be attached. Additional samples can be tested if you'd like to provide them.

Readium version

3.9.0

OS version

iPadOS 26.5

Testing device

iPad Pro 11-inch (M4)

Environment
macOS: 26.5.1
platform: arm64
Xcode 26.5
Build version 17F42
Additional context

A few empirical patterns were observed while probing the failure:

  • Extending or shrinking the selection by one or two words sometimes flips visibility.
  • Selecting a single word within the affected paragraph (without crossing) renders visibly.
Dominant language
Swift
Stars
557
Forks
249
Avg merge
3h 52m
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from readium/swift-toolkit

All issues in readium/swift-toolkit

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.