Skip to content

Commit

Permalink
Fix onSelectionChange event called twice with diferent payload on i…
Browse files Browse the repository at this point in the history
…OS for multiline
  • Loading branch information
tomekzaw committed Feb 15, 2024
1 parent e12b081 commit ef3a8ab
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ios/RCTBaseTextInputView+Markdown.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTBackedTextInputViewProtocol> 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<RCTBackedTextInputDelegate> delegate = backedTextInputView.textInputDelegate;
backedTextInputView.textInputDelegate = nil;
[backedTextInputView setAttributedText:newAttributedText];
backedTextInputView.textInputDelegate = delegate;

// restore original selection
[backedTextInputView setSelectedTextRange:range notifyDelegate:YES];
}
}

// Call the original method
Expand Down

0 comments on commit ef3a8ab

Please sign in to comment.