diff --git a/ios/RCTBaseTextInputView+Markdown.m b/ios/RCTBaseTextInputView+Markdown.m index ad254869..ec2ef82c 100644 --- a/ios/RCTBaseTextInputView+Markdown.m +++ b/ios/RCTBaseTextInputView+Markdown.m @@ -27,10 +27,19 @@ - (void)markdown_updateLocalData { RCTMarkdownUtils *markdownUtils = [self getMarkdownUtils]; if (markdownUtils != nil) { - UITextRange *range = self.backedTextInputView.selectedTextRange; - NSAttributedString *attributedText = [markdownUtils parseMarkdown:self.backedTextInputView.attributedText]; - [self.backedTextInputView setAttributedText:attributedText]; - [self.backedTextInputView setSelectedTextRange:range notifyDelegate:YES]; + id backedTextInputView = self.backedTextInputView; + NSAttributedString *oldAttributedText = backedTextInputView.attributedText; + NSAttributedString *newAttributedText = [markdownUtils parseMarkdown:oldAttributedText]; + UITextRange *range = backedTextInputView.selectedTextRange; + + // update attributed text without emitting onSelectionChange event + id delegate = backedTextInputView.textInputDelegate; + backedTextInputView.textInputDelegate = nil; + [backedTextInputView setAttributedText:newAttributedText]; + backedTextInputView.textInputDelegate = delegate; + + // restore original selection and emit onSelectionChange event + [backedTextInputView setSelectedTextRange:range notifyDelegate:YES]; } // Call the original method