Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/ReactNativeRichTextEditorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSAttributedStringKey, id> *defaultTypingAttributes;
Expand Down
11 changes: 5 additions & 6 deletions ios/ReactNativeRichTextEditorView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ @implementation ReactNativeRichTextEditorView {
NSDictionary<NSNumber *, NSArray<NSNumber *> *> *_blockingStyles;
LinkData *_recentlyActiveLinkData;
NSRange _recentlyActiveLinkRange;
NSRange _recentlyChangedRange;
NSString *_recentlyEmittedString;
MentionParams *_recentlyActiveMentionParams;
NSRange _recentlyActiveMentionRange;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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"];
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions ios/utils/TextInsertionUtils.mm
Original file line number Diff line number Diff line change
@@ -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<NSAttributedStringKey, id>*)additionalAttrs {
Expand All @@ -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<NSAttributedStringKey, id>*)additionalAttrs {
Expand All @@ -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
Loading