From 57375d523326645758c073f1af3876d584bfe0e6 Mon Sep 17 00:00:00 2001 From: szydlovsky <9szydlowski9@gmail.com> Date: Thu, 20 Nov 2025 12:46:09 +0100 Subject: [PATCH 1/2] fix: strange ranges of detected links --- ios/styles/LinkStyle.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ios/styles/LinkStyle.mm b/ios/styles/LinkStyle.mm index 82118e961..5761c1a08 100644 --- a/ios/styles/LinkStyle.mm +++ b/ios/styles/LinkStyle.mm @@ -224,20 +224,22 @@ - (NSRange)getFullLinkRangeAt:(NSUInteger)location { } } - [_input->textView.textStorage + NSString *manualLink = [_input->textView.textStorage attribute:ManualLinkAttributeName atIndex:searchLocation longestEffectiveRange: &manualLinkRange inRange:inputRange ]; - [_input->textView.textStorage + NSString *automaticLink = [_input->textView.textStorage attribute:AutomaticLinkAttributeName atIndex:searchLocation longestEffectiveRange: &automaticLinkRange inRange:inputRange ]; - return manualLinkRange.length == 0 ? automaticLinkRange : manualLinkRange; + return manualLink == nullptr + ? automaticLink == nullptr ? NSMakeRange(0, 0) : automaticLinkRange + : manualLinkRange; } - (void)manageLinkTypingAttributes { From fe7c9beb68c220802d9d7aa203d6aca9bbb93c89 Mon Sep 17 00:00:00 2001 From: szydlovsky <9szydlowski9@gmail.com> Date: Thu, 20 Nov 2025 13:12:10 +0100 Subject: [PATCH 2/2] fix: improve onLinkDetected emitting --- ios/EnrichedTextInputView.mm | 10 +++++++--- ios/styles/LinkStyle.mm | 6 ++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ios/EnrichedTextInputView.mm b/ios/EnrichedTextInputView.mm index 027b5b93f..5b4395eb3 100644 --- a/ios/EnrichedTextInputView.mm +++ b/ios/EnrichedTextInputView.mm @@ -711,9 +711,6 @@ - (void)tryUpdatingActiveStyles { if(detectedLinkData != nullptr) { // emit onLinkeDetected event [self emitOnLinkDetectedEvent:detectedLinkData.text url:detectedLinkData.url range:detectedLinkRange]; - - _recentlyActiveLinkData = detectedLinkData; - _recentlyActiveLinkRange = detectedLinkRange; } if(detectedMentionParams != nullptr) { @@ -812,6 +809,13 @@ - (void)setValue:(NSString *)value { - (void)emitOnLinkDetectedEvent:(NSString *)text url:(NSString *)url range:(NSRange)range { auto emitter = [self getEventEmitter]; if(emitter != nullptr) { + // update recently active link info + LinkData *newLinkData = [[LinkData alloc] init]; + newLinkData.text = text; + newLinkData.url = url; + _recentlyActiveLinkData = newLinkData; + _recentlyActiveLinkRange = range; + emitter->onLinkDetected({ .text = [text toCppString], .url = [url toCppString], diff --git a/ios/styles/LinkStyle.mm b/ios/styles/LinkStyle.mm index 5761c1a08..69e8a2d20 100644 --- a/ios/styles/LinkStyle.mm +++ b/ios/styles/LinkStyle.mm @@ -167,7 +167,6 @@ - (void)addLink:(NSString*)text url:(NSString*)url range:(NSRange)range manual:( } [self manageLinkTypingAttributes]; - [_input anyTextMayHaveBeenModified]; } // get exact link data at the given location if it exists @@ -351,10 +350,9 @@ - (void)handleAutomaticLinks:(NSString *)word inRange:(NSRange)wordRange { } if(addStyle) { [self addLink:word url:regexPassedUrl range:wordRange manual:NO]; + // emit onLinkDetected if style was added + [_input emitOnLinkDetectedEvent:word url:regexPassedUrl range:wordRange]; } - - // emit onLinkDetected - [_input emitOnLinkDetectedEvent:word url:regexPassedUrl range:wordRange]; } }