Skip to content

Commit

Permalink
Fix[input]: unexpected character deletion in some languages
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jul 7, 2024
1 parent 4d60d60 commit 6e17f34
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Natives/TrackedTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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];
}
Expand Down

0 comments on commit 6e17f34

Please sign in to comment.