Skip to content

Commit

Permalink
Make sure to use CGRect
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Aug 27, 2024
1 parent 4af0e52 commit 9f64965
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies: [
func characterIndexes(within rect: CGRect) -> IndexSet
func enumerateLineFragments(for rect: CGRect, strictIntersection: Bool, block: (CGRect, NSRange, inout Bool) -> Void)
func enumerateLineFragments(in range: NSRange, block: (CGRect, NSRange, inout Bool) -> Void)
func boundingRect(for range: NSRange) -> NSRect?
func boundingRect(for range: NSRange) -> CGRect?
```

### `NSTextLayoutManager` Additions
Expand All @@ -49,7 +49,7 @@ func enumerateLineFragments(with provider: NSTextElementProvider, block: (NSText
```swift
func characterIndexes(within rect: CGRect) -> IndexSet
var visibleCharacterIndexes: IndexSet
func boundingRect(for range: NSRange) -> NSRect?
func boundingRect(for range: NSRange) -> CGRect?
```

### `NSRange` and `NSTextRange` Additions
Expand Down
4 changes: 2 additions & 2 deletions Sources/Glyph/NSTextContainer+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ extension NSTextContainer {
}

extension NSTextContainer {
public func boundingRect(for range: NSRange) -> NSRect? {
public func boundingRect(for range: NSRange) -> CGRect? {
if #available(macOS 12.0, iOS 15.0, *), let textLayoutManager {
return textLayoutManager.boundingRect(for: range)
}

return tk1BoundingRect(for: range)
}

private func tk1BoundingRect(for range: NSRange) -> NSRect? {
private func tk1BoundingRect(for range: NSRange) -> CGRect? {
guard let layoutManager else { return nil }

let glyphRange = layoutManager.glyphRange(forCharacterRange: range, actualCharacterRange: nil)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Glyph/NSTextLayoutManager+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ extension NSTextLayoutManager {
}
}

func boundingRect(for range: NSRange) -> NSRect? {
var rect: NSRect? = nil
func boundingRect(for range: NSRange) -> CGRect? {
var rect: CGRect? = nil

enumerateTextLineFragments(in: range, options: [.ensuresLayout]) { lineFragment, lineRect, lineRange, stop in
rect = rect?.union(lineRect) ?? lineRect
Expand Down
2 changes: 1 addition & 1 deletion Sources/Glyph/NSTextView+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension TextView {
}

/// Returns the bounding rectangle for the given text range.
public func boundingRect(for range: NSRange) -> NSRect? {
public func boundingRect(for range: NSRange) -> CGRect? {
#if os(macOS) && !targetEnvironment(macCatalyst)
guard let rect = textContainer?.boundingRect(for: range) else {
return nil
Expand Down

0 comments on commit 9f64965

Please sign in to comment.