Skip to content

feat: paint highlight ranges behind the rendered text (upstream #1218) - #17

Closed
gruckion wants to merge 12 commits into
pingdotgg:fork/t3-mobilefrom
gruckion:t3/highlight-ranges
Closed

gruckion wants to merge 12 commits into
pingdotgg:fork/t3-mobilefrom
gruckion:t3/highlight-ranges

Conversation

@gruckion

@gruckion gruckion commented Nov 20, 2026 •

Copy link
Copy Markdown

This brings software-mansion#1218 to fork/t3-mobile, so that T3 Code can tint the paragraph and the word that read aloud speaks on mobile.

It adds three props to EnrichedMarkdownText:

  • highlights: UTF-16 ranges painted behind the rendered text.
  • onRenderedTextChange: sends the rendered text and its blocks.
  • onHighlightLayout: sends the rect of each range, so that the app can scroll to follow it.

A change to highlights does not parse or lay out the markdown again, and it does not change copied text. The details and limits are in software-mansion#1218.

The port to the fork needed no conflict fixes. The upstream branch needed some, because upstream's Android onDraw now draws text backgrounds.

Screenshots

The paragraph tint and the word tint are two entries in highlights. The screen that drives them is a test screen and is not in this PR.

iOS (iPhone 17 Pro Max, iOS 26.5) Android (Pixel 8, Android 15)
iOS: a quote with its paragraph and the word "like" highlighted Android: a paragraph with the word "while" highlighted

Verification

  • Typecheck, eslint, jest, ktlint and the Android unit tests pass.
  • iOS XCTest runs 69 tests, and 3 of them are new.
  • I ran a test screen on an iPhone 17 Pro Max simulator (iOS 26.5) and a Pixel 8 emulator (Android 15), in light and dark mode. I also ran it in the T3 Code mobile app, with read aloud.

T3 Code uses a tarball of this branch, plus two fork-only fixes (1.2.0-t3.18-35a9c280), in its read-aloud highlight PR, until this lands.

Model and harness: Claude Opus 5.5 in Claude Code.

gruckion and others added 3 commits November 20, 2026 13:00
Add a highlights prop to EnrichedMarkdownText: ranges of the rendered text
with a color, border radius and padding, drawn behind the glyphs on iOS
(TextKit 1 layout manager background pass) and Android (TextView onDraw,
before the text). The text, selection, copy and measuring do not change, and
moving a highlight does not render the Markdown again. In GitHub flavor, code
blocks and tables are tinted as a whole.

onRenderedTextChange reports the text the offsets index into and its blocks.
onHighlightLayout reports each highlight's box when it moves, so a screen can
scroll a highlighted word into view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds native text highlighting based on UTF-16 ranges in rendered Markdown text. iOS and Android report rendered text with block offsets and emit highlight layout rectangles. The TypeScript API exposes the highlight props and callbacks. Tests and documentation cover the API and native coordination. The example app adds a screen that highlights words as playback advances.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: Minimal · up to 35a9c

Highlight ranges and rendered-text callbacks are added on iOS, Android and in the TypeScript API. The earlier problem where a failed render left stale highlight metadata is fixed. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title says the PR paints highlight ranges behind rendered text. The changeset adds the highlights prop, which paints UTF-16 ranges behind rendered text on Android and iOS, plus the related rende…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the PR adds three EnrichedMarkdownText props (highlights, onRenderedTextChange, onHighlightLayout) that paint ranges behind rendered text, and it names the platforms tested. Thi…
Full details: Title check

Explanation

The title says the PR paints highlight ranges behind rendered text. The changeset adds the highlights prop, which paints UTF-16 ranges behind rendered text on Android and iOS, plus the related rendered-text and highlight-layout events. The title matches the main change. It also contains the upstream reference, which is a minor detail.

Full details: Description check

Explanation

The description states the PR adds three EnrichedMarkdownText props (highlights, onRenderedTextChange, onHighlightLayout) that paint ranges behind rendered text, and it names the platforms tested. This matches the changeset, which adds those props on iOS and Android. The description is related to the changeset, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 549465fe-fed5-4205-8369-75647d0cde2c
Commits

Reviewing files that changed from the base of the PR and between edfcf85 and 35a9c28.

Files selected for processing: 2

  • packages/react-native-enriched-markdown/ios/segments/ENRMBlockquoteContainerView.mm
  • packages/react-native-enriched-markdown/ios/segments/ENRMCodeBlockContainerView.m

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@coderabbitai coderabbitai 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.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Update highlight metadata when a render failure clears the text. · EnrichedMarkdownText.kt:328

packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt:328
Minor · Data Integrity & Integration · Quick win

Update highlight metadata when a render failure clears the text.

After a successful render, these failure paths clear text without updating highlightCoordinator. If a listener is then enabled, setEnableRenderedTextChange emits the previous text and blocks although the view is empty. The event contract requires the text that the view shows. (raw.githubusercontent.com)

Route both clears through a helper that also refreshes coordinator state, emits the empty rendered-text snapshot when enabled, and schedules geometry reporting. Keep the existing render-ID and attachment guards.

Also applies to: 346-346

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a3b7ded1-9253-420e-9e4a-a66e58457283
Commits

Reviewing files that changed from the base of the PR and between 497fbe6 and 3431ed0.

Files selected for processing: 45

  • apps/react-native-example/src/App.tsx
  • apps/react-native-example/src/navigation/types.ts
  • apps/react-native-example/src/screens/highlight/HighlightScreen.tsx
  • apps/react-native-example/src/screens/home/HomeScreen.tsx
  • docs-md/API_REFERENCE.md
  • docs/docs/react-native/api-reference/enriched-markdown-text.md
  • packages/react-native-enriched-markdown/__tests__/highlights.test.tsx
  • packages/react-native-enriched-markdown/__tests__/ios/ENRMHighlightCoordinatorTests.mm
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibleMarkdownTextView.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/events/HighlightLayoutEvent.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/events/RenderedTextChangeEvent.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/highlight/HighlightEvents.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/highlight/TextHighlight.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/highlight/TextHighlightCoordinator.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/highlight/TextHighlightPainter.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/CodeBlockContainerView.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/ContainerNodeView.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/segments/TableContainerView.kt
  • packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt
  • packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm
  • packages/react-native-enriched-markdown/ios/EnrichedMarkdownText.mm
  • packages/react-native-enriched-markdown/ios/segments/ENRMCodeBlockContainerView.h
  • packages/react-native-enriched-markdown/ios/segments/ENRMCodeBlockContainerView.m
  • packages/react-native-enriched-markdown/ios/segments/TableContainerView.h
  • packages/react-native-enriched-markdown/ios/segments/TableContainerView.m
  • packages/react-native-enriched-markdown/ios/utils/ENRMHighlightCoordinator.h
  • packages/react-native-enriched-markdown/ios/utils/ENRMHighlightCoordinator.mm
  • packages/react-native-enriched-markdown/ios/utils/ENRMTextHighlight.h
  • packages/react-native-enriched-markdown/ios/utils/ENRMTextHighlight.m
  • packages/react-native-enriched-markdown/ios/utils/ENRMTextHighlightProps.h
  • packages/react-native-enriched-markdown/ios/utils/RuntimeKeys.h
  • packages/react-native-enriched-markdown/ios/utils/RuntimeKeys.m
  • packages/react-native-enriched-markdown/ios/utils/TextViewLayoutManager.h
  • packages/react-native-enriched-markdown/ios/utils/TextViewLayoutManager.mm
  • packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts
  • packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts
  • packages/react-native-enriched-markdown/src/index.tsx
  • packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx
  • packages/react-native-enriched-markdown/src/types/MarkdownTextProps.ts
  • packages/react-native-enriched-markdown/src/types/events.ts
  • packages/react-native-enriched-markdown/src/web/nativeProps.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

gruckion and others added 8 commits November 24, 2026 14:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on its own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ackgrounds

A line background span added after the text's own draws the highlight once
those backgrounds are down and before the glyphs and the selection. Text
that is not Spannable keeps drawing it before the text. Boxes that touch on
one line, such as a trailing space, join into one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gruckion

Copy link
Copy Markdown
Author

Outside-diff finding on EnrichedMarkdownText.kt:328 (a failed render clears the text without updating highlights): fixed in 214f1b7. Both failure paths now refresh the rendered text and emit the change.

gruckion added a commit to gruckion/t3code that referenced this pull request Nov 24, 2026
Packs pingdotgg/enriched-markdown#17 at edfcf852 with the fork's iOS fixes
(commit 35a9c280).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The feature is shown in the PR description instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gruckion
gruckion force-pushed the t3/highlight-ranges branch from 35a9c28 to 3772a92 Compare November 24, 2026 17:16
Yash-Singh1 pushed a commit that referenced this pull request Nov 25, 2026
Adds a highlights prop that paints colored ranges behind the rendered text on
iOS and Android, onRenderedTextChange, which reports the rendered plain text
and its blocks, and onHighlightLayout, which reports where the ranges were
painted, so a reader can follow along and scroll to them.

From software-mansion#1218 at 5f24630 (#17)
Upstream: software-mansion#1218
Yash-Singh1 pushed a commit that referenced this pull request Nov 26, 2026
Adds a highlights prop that paints colored ranges behind the rendered text on
iOS and Android, onRenderedTextChange, which reports the rendered plain text
and its blocks, and onHighlightLayout, which reports where the ranges were
painted, so a reader can follow along and scroll to them.

From software-mansion#1218 at 5f24630 (#17)
Upstream: software-mansion#1218
@gruckion

Copy link
Copy Markdown
Author

Closing: highlight ranges ship to T3 through t3/mobile-tarball (11817aa), squashed from software-mansion#1218, so this PR is not needed.

@gruckion gruckion closed this Nov 26, 2026
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.

1 participant