Skip to content

Commit 6b3ebd5

Browse files
authored
fix: remove zero width space utils accidental autofocus (#134)
1 parent 2bba2e1 commit 6b3ebd5

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

ios/utils/ZeroWidthSpaceUtils.mm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ + (void)removeSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor {
6262
}
6363
}
6464

65-
// fix the selection
66-
[editor->textView reactFocus];
67-
editor->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length);
65+
// fix the selection if needed
66+
if(editor->textView.focused) {
67+
[editor->textView reactFocus];
68+
editor->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length);
69+
}
6870
}
6971

7072
+ (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor {
@@ -109,9 +111,11 @@ + (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor {
109111
[TextInsertionUtils insertText:@"\u200B" at:lastRange.location additionalAttributes:nullptr editor:editor withSelection:NO];
110112
}
111113

112-
// fix the selection
113-
[editor->textView reactFocus];
114-
editor->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length);
114+
// fix the selection if needed
115+
if(editor->textView.focused) {
116+
[editor->textView reactFocus];
117+
editor->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length);
118+
}
115119
}
116120

117121
+ (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text editor:(id)editor {

0 commit comments

Comments
 (0)