Skip to content

Commit 8ab46b2

Browse files
committed
Fixed a crash that may result if layoutManager and textStorage happens to be out of sync
1 parent 9f862d6 commit 8ab46b2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Proton/Sources/Swift/Core/RichTextView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,11 @@ class RichTextView: AutogrowingTextView {
829829
}
830830

831831
override func caretRect(for position: UITextPosition) -> CGRect {
832-
guard isEditable else {
832+
// layoutManager.numberOfGlyphs check is required to prevent cases where selectedRange is accessed
833+
// while TextProcessor is processing and contents are changed to prevent a crash that may result when
834+
// this is not same as textStorage.length
835+
guard isEditable,
836+
layoutManager.numberOfGlyphs == textStorage.length else {
833837
return super.caretRect(for: position)
834838
}
835839

0 commit comments

Comments
 (0)