From 63cc672cd1bcc408b3a5158816985c82308e5f83 Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Fri, 20 Dec 2024 07:39:27 -0500 Subject: [PATCH] Subtle bug around line fragment computations --- .../NSTextLayoutFragment+Additions.swift | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Sources/Glyph/NSTextLayoutFragment+Additions.swift b/Sources/Glyph/NSTextLayoutFragment+Additions.swift index 86a5a79..bdbf3fa 100644 --- a/Sources/Glyph/NSTextLayoutFragment+Additions.swift +++ b/Sources/Glyph/NSTextLayoutFragment+Additions.swift @@ -35,15 +35,10 @@ extension NSTextLineFragment { for index in (start.. point.x { + if span.upperBound >= point.x { end = min(index + 1, length) break } - - if span.upperBound == point.x { - end = index - break - } } guard let end else { return nil } @@ -85,16 +80,24 @@ extension NSTextLayoutFragment { precondition(location >= 0) precondition(location != NSNotFound) + var locationOffset = location + for textLineFragment in textLineFragments { + // we have to shift to compute overlap, and then shift back to compute the span let bounds = textLineFragment.typographicBounds.offsetBy(dx: origin.x, dy: origin.y) - - let overlap = bounds.intersection(rect) + let overlap = bounds.intersection(rect).offsetBy(dx: -origin.x, dy: -origin.y) let span: Range = overlap.minX..