Fix crash when hovering with the cursor over certain text views
Closes #183
This commit is contained in:
parent
a703b7cc0a
commit
035034430e
|
@ -221,7 +221,9 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
|
||||||
let charIndex = lineFragment.characterIndex(for: pointInLineFragment)
|
let charIndex = lineFragment.characterIndex(for: pointInLineFragment)
|
||||||
|
|
||||||
var range = NSRange()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
// lineFragment.attributedString is the NSTextLayoutFragment's string, and so range is in its index space
|
// lineFragment.attributedString is the NSTextLayoutFragment's string, and so range is in its index space
|
||||||
|
|
Loading…
Reference in New Issue