ContentTextView cleanup
This commit is contained in:
parent
af2e95ea39
commit
50dd785ef8
|
@ -197,13 +197,17 @@ class ContentTextView: LinkTextView, BaseEmojiLabel {
|
||||||
let locationInTextContainer = CGPoint(x: point.x - textContainerInset.left, y: point.y - textContainerInset.top)
|
let locationInTextContainer = CGPoint(x: point.x - textContainerInset.left, y: point.y - textContainerInset.top)
|
||||||
if #available(iOS 16.0, *),
|
if #available(iOS 16.0, *),
|
||||||
let textLayoutManager {
|
let textLayoutManager {
|
||||||
guard let fragment = textLayoutManager.textLayoutFragment(for: point),
|
guard let fragment = textLayoutManager.textLayoutFragment(for: locationInTextContainer) else {
|
||||||
let lineFragment = fragment.textLineFragments.first(where: { lineFragment in
|
return nil
|
||||||
lineFragment.typographicBounds.offsetBy(dx: fragment.layoutFragmentFrame.minX, dy: fragment.layoutFragmentFrame.minY).contains(point)
|
}
|
||||||
|
let pointInLayoutFragment = CGPoint(x: locationInTextContainer.x - fragment.layoutFragmentFrame.minX, y: locationInTextContainer.y - fragment.layoutFragmentFrame.minY)
|
||||||
|
guard let lineFragment = fragment.textLineFragments.first(where: { lineFragment in
|
||||||
|
lineFragment.typographicBounds.contains(pointInLayoutFragment)
|
||||||
}) else {
|
}) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let charIndex = lineFragment.characterIndex(for: point)
|
let pointInLineFragment = CGPoint(x: pointInLayoutFragment.x - lineFragment.typographicBounds.minX, y: pointInLayoutFragment.y - lineFragment.typographicBounds.minY)
|
||||||
|
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 {
|
guard let link = lineFragment.attributedString.attribute(.link, at: charIndex, longestEffectiveRange: &range, in: lineFragment.attributedString.fullRange) as? URL else {
|
||||||
|
@ -332,7 +336,7 @@ extension ContentTextView: UIContextMenuInteractionDelegate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// .standard because i have no idea what the difference is
|
// .standard because i have no idea what the difference is
|
||||||
textLayoutManager.enumerateTextSegments(in: textRange, type: .standard, options: []) { range, rect, float, textContainer in
|
textLayoutManager.enumerateTextSegments(in: textRange, type: .standard, options: .rangeNotRequired) { range, rect, float, textContainer in
|
||||||
rects.append(rect)
|
rects.append(rect)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue