From 50dd785ef8581ad19f7e06f33a08e070728ebf94 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 31 Jul 2022 19:39:14 -0400 Subject: [PATCH] ContentTextView cleanup --- Tusker/Views/ContentTextView.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 27de5184bd..16cc458fe0 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -197,13 +197,17 @@ class ContentTextView: LinkTextView, BaseEmojiLabel { let locationInTextContainer = CGPoint(x: point.x - textContainerInset.left, y: point.y - textContainerInset.top) if #available(iOS 16.0, *), let textLayoutManager { - guard let fragment = textLayoutManager.textLayoutFragment(for: point), - let lineFragment = fragment.textLineFragments.first(where: { lineFragment in - lineFragment.typographicBounds.offsetBy(dx: fragment.layoutFragmentFrame.minX, dy: fragment.layoutFragmentFrame.minY).contains(point) + guard let fragment = textLayoutManager.textLayoutFragment(for: locationInTextContainer) else { + return nil + } + 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 { 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() 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 } // .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) return true }