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] {