From 6e6841d1db9174dbbdc7918ab08b50fa7a83f381 Mon Sep 17 00:00:00 2001 From: Jerrydu <35886844+jerrydudu@users.noreply.github.com> Date: Thu, 2 Dec 2021 16:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8B=B1=E6=96=87=E8=81=94?= =?UTF-8?q?=E6=83=B3=E8=AF=8D=E5=A4=9A=E4=BD=99=E7=A9=BA=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YYText/YYTextView.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/YYText/YYTextView.m b/YYText/YYTextView.m index 01b1629a..33ffca64 100644 --- a/YYText/YYTextView.m +++ b/YYText/YYTextView.m @@ -1422,14 +1422,11 @@ - (CGRect)_convertRectFromLayout:(CGRect)rect { /// The caller should make sure the `range` and `text` are valid before call this method. - (void)_replaceRange:(YYTextRange *)range withText:(NSString *)text notifyToDelegate:(BOOL)notify{ if (NSEqualRanges(range.asRange, _selectedTextRange.asRange)) { - if (notify) [_inputDelegate selectionWillChange:self]; NSRange newRange = NSMakeRange(0, 0); newRange.location = _selectedTextRange.start.offset + text.length; _selectedTextRange = [YYTextRange rangeWithRange:newRange]; - if (notify) [_inputDelegate selectionDidChange:self]; } else { if (range.asRange.length != text.length) { - if (notify) [_inputDelegate selectionWillChange:self]; NSRange unionRange = NSIntersectionRange(_selectedTextRange.asRange, range.asRange); if (unionRange.length == 0) { // no intersection @@ -1462,15 +1459,16 @@ - (void)_replaceRange:(YYTextRange *)range withText:(NSString *)text notifyToDel _selectedTextRange = [YYTextRange rangeWithRange:newRange]; } } - _selectedTextRange = [self _correctedTextRange:_selectedTextRange]; - if (notify) [_inputDelegate selectionDidChange:self]; } } + if (notify) [_inputDelegate selectionWillChange:self]; if (notify) [_inputDelegate textWillChange:self]; NSRange newRange = NSMakeRange(range.asRange.location, text.length); [_innerText replaceCharactersInRange:range.asRange withString:text]; [_innerText yy_removeDiscontinuousAttributesInRange:newRange]; + _selectedTextRange = [self _correctedTextRange:_selectedTextRange]; if (notify) [_inputDelegate textDidChange:self]; + if (notify) [_inputDelegate selectionDidChange:self]; } /// Save current typing attributes to the attributes holder.