From 561858faff81f1085c031db2db00b09ca52b2a1c Mon Sep 17 00:00:00 2001 From: Marcin Krzyzanowski Date: Sat, 18 May 2024 16:57:20 +0200 Subject: [PATCH] typographicBounds --- Sources/STTextKitPlus/NSTextContentManager.swift | 2 +- Sources/STTextKitPlus/NSTextLayoutManager.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/STTextKitPlus/NSTextContentManager.swift b/Sources/STTextKitPlus/NSTextContentManager.swift index 9f893de..b2c5fcf 100644 --- a/Sources/STTextKitPlus/NSTextContentManager.swift +++ b/Sources/STTextKitPlus/NSTextContentManager.swift @@ -90,7 +90,7 @@ public extension NSTextContentManager { precondition(range.isEmpty == false) } - if range != nil, range?.isEmpty == true { + if let range, range.isEmpty { return nil } diff --git a/Sources/STTextKitPlus/NSTextLayoutManager.swift b/Sources/STTextKitPlus/NSTextLayoutManager.swift index 59307b5..68a067b 100644 --- a/Sources/STTextKitPlus/NSTextLayoutManager.swift +++ b/Sources/STTextKitPlus/NSTextLayoutManager.swift @@ -77,6 +77,13 @@ extension NSTextLayoutManager { } extension NSTextLayoutManager { + + /// Typographic bounds of the range. + /// - Parameter textRange: The range. + /// - Returns: Typographic bounds of the range. + public func typographicBounds(in textRange: NSTextRange) -> CGRect? { + textSegmentFrame(in: textRange, type: .standard, options: [.upstreamAffinity, .rangeNotRequired]) + } /// A text segment is both logically and visually contiguous portion of the text content inside a line fragment. public func textSegmentFrame(at location: NSTextLocation, type: NSTextLayoutManager.SegmentType, options: SegmentOptions = [.upstreamAffinity]) -> CGRect? {