From da0ed34a367b938be61718e7ff83a736f076da0e Mon Sep 17 00:00:00 2001 From: rztime Date: Tue, 23 Jan 2024 14:59:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AB=E5=B0=BE=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF=E5=B8=A6=E6=9D=A5?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RZRichTextView/Classes/AttributedStringRich.swift | 8 +++++++- RZRichTextView/Classes/RZRichTextView.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RZRichTextView/Classes/AttributedStringRich.swift b/RZRichTextView/Classes/AttributedStringRich.swift index d65e322..10f74b3 100644 --- a/RZRichTextView/Classes/AttributedStringRich.swift +++ b/RZRichTextView/Classes/AttributedStringRich.swift @@ -23,9 +23,13 @@ public extension RZRichTextBase where T : NSAttributedString { let all = self.allParapraghRange() var res: [NSRange] = [] for (idx, tempRange) in all.enumerated() { - if idx == all.count - 1 { + if let _ = range.intersection(tempRange) { + res.append(tempRange) + } else if idx == all.count - 1 { if range.location >= tempRange.location && range.location <= tempRange.rt.maxLength() { res.append(tempRange) + } else if range.upperBound >= tempRange.location && range.upperBound <= tempRange.upperBound { + res.append(tempRange) } } else if range.location >= tempRange.rt.maxLength() { @@ -33,6 +37,8 @@ public extension RZRichTextBase where T : NSAttributedString { res.append(tempRange) } else if range.location < tempRange.location && range.rt.maxLength() > tempRange.location { res.append(tempRange) + } else if range.upperBound >= tempRange.location && range.upperBound <= tempRange.upperBound { + res.append(tempRange) } } return res diff --git a/RZRichTextView/Classes/RZRichTextView.swift b/RZRichTextView/Classes/RZRichTextView.swift index 851ea09..4685c5b 100644 --- a/RZRichTextView/Classes/RZRichTextView.swift +++ b/RZRichTextView/Classes/RZRichTextView.swift @@ -549,7 +549,7 @@ public extension RZRichTextView { self.typingAttributes = self.lastTexttypingAttributes } } - self.lastCursorIsEnd = self.selectedRange.location == self.textStorage.length + self.lastCursorIsEnd = self.selectedRange.location == self.textStorage.length || self.selectedRange.upperBound == self.textStorage.length } /// 获取真实的属性 func getRealTypingAttributes() -> [NSAttributedString.Key: Any] {