diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index c522481b..300c79b7 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -578,7 +578,9 @@ - (void)textViewDidChange:(UITextView *)textView { if (textView.markedTextRange) return; if (self.maxLength) { + UITextRange *range = textView.selectedTextRange; textView.text = [self limitToHansMaxLength:self.maxLength.unsignedIntValue text:textView.text]; + textView.selectedTextRange = range; } if (self.onTextChange) { self.onTextChange(textView.text, self); @@ -611,7 +613,9 @@ - (NSString *)limitToHansMaxLength:(NSUInteger)maxLen text:(NSString *)text { - (void)textFieldDidChange:(UITextField *)textField { if (self.maxLength) { + UITextRange *range = textField.selectedTextRange; textField.text = [self limitToHansMaxLength:self.maxLength.unsignedIntValue text:textField.text]; + textField.selectedTextRange = range; } if (self.onTextChange) { self.onTextChange(textField.text, self);