Skip to content

Commit

Permalink
Update boundingRect usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Dec 16, 2024
1 parent bc5895d commit a80c9f1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Ligature/UTF16CodePointTextViewTextTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public struct UTF16CodePointTextViewTextTokenizer {
}

extension UTF16CodePointTextViewTextTokenizer {
public func location(for position: Position) -> CGFloat? {
textView.boundingRect(for: NSRange(position..<position))?.minX
public func boundingRect(for range: NSRange) -> CGRect? {
textView.boundingRect(for: range)
}

/// A variant of position(from:toBoundary:inDirection:) that can take alignment into account.
Expand Down Expand Up @@ -127,7 +127,7 @@ extension UTF16CodePointTextViewTextTokenizer {
return self.position(from: position, toBoundary: granularity, inDirection: resolvedDir, alignment: alignment)
case (.character, .layout(.down)):
guard
let alignment = alignment ?? location(for: position),
let alignment = alignment ?? boundingRect(for: NSRange(position..<position))?.origin.x,
let nextFragment = textView.textContainer?.lineFragment(for: position, offset: 1)
else {
return nil
Expand All @@ -138,7 +138,7 @@ extension UTF16CodePointTextViewTextTokenizer {
// because we are iterating backwards, we have to advance by one character so we are sure we
// include the fragment that "position" is in
guard
let alignment = alignment ?? location(for: position),
let alignment = alignment ?? boundingRect(for: NSRange(position..<position))?.origin.x,
let start = self.position(from: position, toBoundary: .character, inDirection: .storage(.forward)),
let nextFragment = textView.textContainer?.lineFragment(for: start, offset: -1)
else {
Expand Down

0 comments on commit a80c9f1

Please sign in to comment.