Skip to content

Commit

Permalink
Fix onSelectionChange event called twice with different payload on …
Browse files Browse the repository at this point in the history
…iOS for multiline (#192)
  • Loading branch information
tomekzaw authored Feb 22, 2024
1 parent 02c4262 commit 2c6a7b4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ios/RCTBaseTextInputView+Markdown.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTBackedTextInputViewProtocol> backedTextInputView = self.backedTextInputView;
NSAttributedString *oldAttributedText = backedTextInputView.attributedText;
NSAttributedString *newAttributedText = [markdownUtils parseMarkdown:oldAttributedText];
UITextRange *range = backedTextInputView.selectedTextRange;

// update attributed text without emitting onSelectionChange event
id<RCTBackedTextInputDelegate> 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
Expand Down

0 comments on commit 2c6a7b4

Please sign in to comment.