Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ - (BOOL)textField:(__unused UITextField *)textField
return YES;
}

// Clamp the range to the current text length to avoid NSRangeException.
NSUInteger textLength = _backedTextInputView.attributedText.length;
if (range.location > textLength) {
return NO;
}
if (range.location + range.length > textLength) {
range = NSMakeRange(range.location, textLength - range.location);
}

NSMutableAttributedString *attributedString = [_backedTextInputView.attributedText mutableCopy];
[attributedString replaceCharactersInRange:range withString:newText];
[_backedTextInputView setAttributedText:[attributedString copy]];
Expand Down Expand Up @@ -292,8 +301,13 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang
return NO;
}

if (range.location + range.length > _backedTextInputView.text.length) {
range = NSMakeRange(range.location, _backedTextInputView.text.length - range.location);
// Clamp the range to the current text length to avoid NSRangeException.
NSUInteger textLength = _backedTextInputView.attributedText.length;
if (range.location > textLength) {
return NO;
}
if (range.location + range.length > textLength) {
range = NSMakeRange(range.location, textLength - range.location);
} else if ([newText isEqualToString:text]) {
_textDidChangeIsComing = YES;
return YES;
Expand Down
Loading