diff --git a/ios/ReactNativeRichTextEditorView.h b/ios/ReactNativeRichTextEditorView.h index 5407a5553..77c78dd05 100644 --- a/ios/ReactNativeRichTextEditorView.h +++ b/ios/ReactNativeRichTextEditorView.h @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @interface ReactNativeRichTextEditorView : RCTViewComponentView { @public UITextView *textView; + @public NSRange recentlyChangedRange; @public EditorConfig *config; @public EditorParser *parser; @public NSMutableDictionary *defaultTypingAttributes; diff --git a/ios/ReactNativeRichTextEditorView.mm b/ios/ReactNativeRichTextEditorView.mm index 25ef9378b..4e7ee0abd 100644 --- a/ios/ReactNativeRichTextEditorView.mm +++ b/ios/ReactNativeRichTextEditorView.mm @@ -30,7 +30,6 @@ @implementation ReactNativeRichTextEditorView { NSDictionary *> *_blockingStyles; LinkData *_recentlyActiveLinkData; NSRange _recentlyActiveLinkRange; - NSRange _recentlyChangedRange; NSString *_recentlyEmittedString; MentionParams *_recentlyActiveMentionParams; NSRange _recentlyActiveMentionRange; @@ -74,7 +73,7 @@ - (void)setDefaults { _activeStyles = [[NSMutableSet alloc] init]; _recentlyActiveLinkRange = NSMakeRange(0, 0); _recentlyActiveMentionRange = NSMakeRange(0, 0); - _recentlyChangedRange = NSMakeRange(0, 0); + recentlyChangedRange = NSMakeRange(0, 0); _recentlyEmittedString = @""; _recentlyEmittedHtml = @""; emitHtml = NO; @@ -951,11 +950,11 @@ - (void)anyTextMayHaveBeenModified { // list item all characters removal fix UnorderedListStyle *uStyle = stylesDict[@([UnorderedListStyle getStyleType])]; if(uStyle != nullptr) { - [uStyle handleListItemWithChangeRange:_recentlyChangedRange]; + [uStyle handleListItemWithChangeRange:recentlyChangedRange]; } OrderedListStyle *oStyle = stylesDict[@([OrderedListStyle getStyleType])]; if(oStyle != nullptr) { - [oStyle handleListItemWithChangeRange:_recentlyChangedRange]; + [oStyle handleListItemWithChangeRange:recentlyChangedRange]; } // inline code on newlines fix @@ -971,7 +970,7 @@ - (void)anyTextMayHaveBeenModified { } // modified words handling - NSArray *modifiedWords = [WordsUtils getAffectedWordsFromText:textView.textStorage.string modificationRange:_recentlyChangedRange]; + NSArray *modifiedWords = [WordsUtils getAffectedWordsFromText:textView.textStorage.string modificationRange:recentlyChangedRange]; if(modifiedWords != nullptr) { for(NSDictionary *wordDict in modifiedWords) { NSString *wordText = (NSString *)[wordDict objectForKey:@"word"]; @@ -1037,7 +1036,7 @@ - (void)textViewDidEndEditing:(UITextView *)textView { } - (bool)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { - _recentlyChangedRange = NSMakeRange(range.location, text.length); + recentlyChangedRange = NSMakeRange(range.location, text.length); BOOL rejectTextChanges = NO; diff --git a/ios/utils/TextInsertionUtils.mm b/ios/utils/TextInsertionUtils.mm index da7a5fdf4..fbf3e123e 100644 --- a/ios/utils/TextInsertionUtils.mm +++ b/ios/utils/TextInsertionUtils.mm @@ -1,5 +1,7 @@ #import "TextInsertionUtils.h" #import "UIView+React.h" +#import "EditorManager.h" +#import "ReactNativeRichTextEditorView.h" @implementation TextInsertionUtils + (void)insertText:(NSString*)text inView:(UITextView*)textView at:(NSInteger)index additionalAttributes:(NSDictionary*)additionalAttrs { @@ -24,6 +26,11 @@ + (void)insertText:(NSString*)text inView:(UITextView*)textView at:(NSInteger)in [textView reactFocus]; textView.selectedRange = NSMakeRange(index + text.length, 0); + + ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)[EditorManager sharedManager].currentEditor; + if(typedEditor != nullptr) { + typedEditor->recentlyChangedRange = NSMakeRange(index, text.length); + } } + (void)replaceText:(NSString*)text inView:(UITextView*)textView at:(NSRange)range additionalAttributes:(NSDictionary*)additionalAttrs { @@ -34,5 +41,10 @@ + (void)replaceText:(NSString*)text inView:(UITextView*)textView at:(NSRange)ran [textView reactFocus]; textView.selectedRange = NSMakeRange(range.location + text.length, 0); + + ReactNativeRichTextEditorView *typedEditor = (ReactNativeRichTextEditorView *)[EditorManager sharedManager].currentEditor; + if(typedEditor != nullptr) { + typedEditor->recentlyChangedRange = NSMakeRange(range.location, text.length); + } } @end