From 6e17f346e766b453d7539c8788a1e5f1a32f8f9f Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Sun, 7 Jul 2024 13:09:47 +0700 Subject: [PATCH] Fix[input]: unexpected character deletion in some languages --- Natives/TrackedTextField.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Natives/TrackedTextField.m b/Natives/TrackedTextField.m index 5155aa7d07..5b413cd666 100644 --- a/Natives/TrackedTextField.m +++ b/Natives/TrackedTextField.m @@ -108,10 +108,10 @@ - (BOOL)hasText { - (NSRange)insertFilteredText:(NSString *)text { int cursorPos = [super offsetFromPosition:self.beginningOfDocument toPosition:self.selectedTextRange.start]; - // This also makes sure that lastTextPos != cursorPos (text should never be empty) - if (self.lastTextPos - cursorPos == text.length) { + int off = self.lastTextPos - cursorPos; + if (off > 0) { // Handle text markup by first deleting N amount of characters equal to the replaced text - [self sendMultiBackspaces:text.length]; + [self sendMultiBackspaces:off]; } // What else is done by past-autocomplete (insert a space after autocompletion) // See -[TrackedTextField replaceRangeWithTextWithoutClosingTyping:replacementText:] @@ -126,13 +126,14 @@ - (NSRange)insertFilteredText:(NSString *)text { - (id)replaceRangeWithTextWithoutClosingTyping:(UITextRange *)range replacementText:(NSString *)text { - int length = [super offsetFromPosition:range.start toPosition:range.end]; + int oldLength = [super offsetFromPosition:range.start toPosition:range.end]; // Delete the range of needs for autocompletion - [self sendMultiBackspaces:length]; + [self sendMultiBackspaces:oldLength]; // Insert the autocompleted text [self sendText:text]; + self.lastTextPos += text.length - oldLength; return [super replaceRangeWithTextWithoutClosingTyping:range replacementText:text]; }