From a87fb842608231e62c54d8d68823977dd087c853 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 24 Mar 2022 18:11:59 +0800 Subject: [PATCH] iOS: fix when input set maxLength, delete text in middel, the selection move to end --- doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 4 ++++ 1 file changed, 4 insertions(+) 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);