Fix crash when hovering with the cursor over certain text views

Closes #183
This commit is contained in:
Shadowfacts 2022-10-09 20:39:17 -04:00
parent a703b7cc0a
commit 035034430e
1 changed files with 3 additions and 1 deletions

View File

@ -221,7 +221,9 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
let charIndex = lineFragment.characterIndex(for: pointInLineFragment)
var range = NSRange()
guard let link = lineFragment.attributedString.attribute(.link, at: charIndex, longestEffectiveRange: &range, in: lineFragment.attributedString.fullRange) as? URL else {
// sometimes characterIndex(for:) returns NSNotFound even for points that are in the line fragment's typographic bounds (see #183), so we check just in case
guard charIndex != NSNotFound,
let link = lineFragment.attributedString.attribute(.link, at: charIndex, longestEffectiveRange: &range, in: lineFragment.attributedString.fullRange) as? URL else {
return nil
}
// lineFragment.attributedString is the NSTextLayoutFragment's string, and so range is in its index space