diff --git a/ios/RCTBaseTextInputView+Markdown.m b/ios/RCTBaseTextInputView+Markdown.m index ad254869..cff941d8 100644 --- a/ios/RCTBaseTextInputView+Markdown.m +++ b/ios/RCTBaseTextInputView+Markdown.m @@ -27,10 +27,21 @@ - (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]; + if (![newAttributedText isEqualToAttributedString:oldAttributedText]) { + UITextRange *range = backedTextInputView.selectedTextRange; + + // update attributed text without calling textInputDidChangeSelection and emitting onSelectionChange event + id delegate = backedTextInputView.textInputDelegate; + backedTextInputView.textInputDelegate = nil; + [backedTextInputView setAttributedText:newAttributedText]; + backedTextInputView.textInputDelegate = delegate; + + // restore original selection + [backedTextInputView setSelectedTextRange:range notifyDelegate:YES]; + } } // Call the original method