Skip to content

fix(iOS, Android): split manual links when newline inserted in link - #624

Open
kacperzolkiewski wants to merge 13 commits into
mainfrom
@kacperzolkiewski/fix-onlink-detected
Open

kacperzolkiewski wants to merge 13 commits into
mainfrom
@kacperzolkiewski/fix-onlink-detected

Conversation

@kacperzolkiewski

@kacperzolkiewski kacperzolkiewski commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes: #556

Test Plan

Run reproduction steps from issue: #556
Issue should be resolved

Screenshots / Videos

Screen.Recording.2026-06-02.at.12.24.28.mov

Compatibility

OS Implemented
iOS ✅
Android ✅

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@kacperzolkiewski
kacperzolkiewski marked this pull request as ready for review June 2, 2026 10:26
@kacperzolkiewski
kacperzolkiewski requested review from exploIF and szydlovsky and removed request for szydlovsky June 2, 2026 10:26
@kacperzolkiewski kacperzolkiewski changed the title fix(android): split manual links when newline inserted in link fix: split manual links when newline inserted in link Jun 2, 2026
Comment thread ios/EnrichedTextInputView.mm Resolved

@szydlovsky szydlovsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

iOS works fine

…ftware-mansion/react-native-enriched into @kacperzolkiewski/fix-onlink-detected

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses incorrect onLinkDetected behavior when a manually-inserted link is split across multiple lines by inserting newlines, ensuring link spans/events reflect the split segments correctly on both iOS and Android.

Changes:

  • iOS: refreshes manual link metadata so LinkData.text matches the current text in the refreshed range.
  • Android: splits manual link spans when newline characters are inserted inside a manual link, and de-duplicates onLinkDetected using (text, url, start, end) rather than just (text, url).
  • Example app: initializes selection state with a non-undefined default.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ios/styles/LinkStyle.mm Updates refreshed manual link metadata to use the current substring for LinkData.text.
ios/EnrichedTextInputView.mm Avoids redundant/early active-style updates during text changes to prevent stale link detection.
apps/example/src/hooks/useEditorState.ts Provides a default {start,end,text} selection value instead of undefined.
android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSelection.kt Improves link-detected event de-duping by including visible start/end offsets.
android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt Splits manual link spans on newline insertion and factors span-application into a helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ios/EnrichedTextInputView.mm Resolved
Comment thread ios/EnrichedTextInputView.mm Resolved

@szydlovsky szydlovsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@exploIF exploIF left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested on device

Android emulator (Pixel 9, API 36) and iOS simulator (iOS 26.2), example app → Test screen. Tested this PR merged onto current main; iOS multi-word rows compared against a plain main build. Values are onLinkDetected payloads (text start–end).

Scenario Platform main This PR
One-word link "Hello" split into H/e/l/l/o with Enter (#556 repro) Android ❌ Treated as one link (per #556, not re-run) ✅ Each piece reported separately: e 2–3, l 4–5, l 6–7, o 8–9
One-word link "Hello" split into H/e/l/l/o with Enter (#556 repro) iOS ❌ Every piece reports text Hello (per #556, not re-run) ✅ H 0–1, e 2–3, l 4–5, l 6–7, o 8–9
Multi-word link "foo bar baz", move cursor through it (no edits) iOS ✅ Single link: foo bar baz 0–11 ❌ Reported per word: baz 8–11, bar 4–7; spaces report a 1-char range with stale text foo bar baz
Same link, press Enter after "foo", put cursor in "bar" iOS ⚠️ foo bar baz 4–12 (range correct, text stale: the original bug) ❌ bar 5–8 (text and range wrong; HTML has bar baz as one link)
Multi-word link "foo bar baz", same steps Android — ✅ Single link before the split; bar baz 4–12 after it, matching the HTML
Event fired right after Enter Android — ⚠️ A stale foo\n bar baz 0–12 fires first; the correct event follows ~5 ms later

@szydlovsky
szydlovsky requested a review from exploIF November 9, 2026 18:26
@szydlovsky szydlovsky changed the title fix: split manual links when newline inserted in link fix(iOS, Android): split manual links when newline inserted in link Nov 12, 2026

This branch has not been deployed

No deployments
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.

onLinkDetected invalid behavior when splitting a link over multiple lines

4 participants