From 6765c942e5e7dce87e4f10b3ab842c8d9e065fec Mon Sep 17 00:00:00 2001 From: szydlovsky <9szydlowski9@gmail.com> Date: Fri, 29 Aug 2025 12:29:32 +0200 Subject: [PATCH] fix: remove zero width space utils accidental autofocus --- ios/utils/ZeroWidthSpaceUtils.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ios/utils/ZeroWidthSpaceUtils.mm b/ios/utils/ZeroWidthSpaceUtils.mm index 25c4f9c27..2acee377f 100644 --- a/ios/utils/ZeroWidthSpaceUtils.mm +++ b/ios/utils/ZeroWidthSpaceUtils.mm @@ -62,9 +62,11 @@ + (void)removeSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { } } - // fix the selection - [editor->textView reactFocus]; - editor->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length); + // fix the selection if needed + if(editor->textView.focused) { + [editor->textView reactFocus]; + editor->textView.selectedRange = NSMakeRange(preRemoveSelection.location + postRemoveOffset, preRemoveSelection.length); + } } + (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { @@ -109,9 +111,11 @@ + (void)addSpacesIfNeededInEditor:(ReactNativeRichTextEditorView *)editor { [TextInsertionUtils insertText:@"\u200B" at:lastRange.location additionalAttributes:nullptr editor:editor withSelection:NO]; } - // fix the selection - [editor->textView reactFocus]; - editor->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length); + // fix the selection if needed + if(editor->textView.focused) { + [editor->textView reactFocus]; + editor->textView.selectedRange = NSMakeRange(preAddSelection.location + postAddOffset, preAddSelection.length); + } } + (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text editor:(id)editor {