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 82118e961..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 @@ -224,20 +223,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 { @@ -349,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]; } }