Skip to content

Commit e38bdcf

Browse files
committed
Make watchOS compile
1 parent 8e3c3d3 commit e38bdcf

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Sources/RichTextKit/Component/RichTextViewComponent+Paragraph.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ public extension RichTextViewComponent {
2929
/// selected paragraphs. If many paragraphs are selected,
3030
/// it will only affect the first one.
3131
func setRichTextParagraphStyle(_ style: NSParagraphStyle) {
32-
guard let storage = textStorageWrapper else { return }
3332
let range = lineRange(for: selectedRange)
3433
guard range.length > 0 else { return }
35-
storage.addAttribute(.paragraphStyle, value: style, range: range)
34+
#if os(watchOS)
35+
setRichTextAttribute(.paragraphStyle, to: style, at: range)
36+
#else
37+
textStorageWrapper?.addAttribute(.paragraphStyle, value: style, range: range)
38+
#endif
3639
}
3740
}

Sources/RichTextKit/Component/RichTextViewComponent+Ranges.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import Foundation
99

1010
extension RichTextViewComponent {
1111

12+
var notFoundRange: NSRange {
13+
.init(location: NSNotFound, length: 0)
14+
}
15+
1216
/// Get the line range at a certain text location.
1317
func lineRange(at location: Int) -> NSRange {
18+
#if os(watchOS)
19+
return notFoundRange
20+
#else
1421
guard
1522
let manager = layoutManagerWrapper,
1623
let storage = textStorageWrapper
@@ -19,11 +26,14 @@ extension RichTextViewComponent {
1926
let locationRange = NSRange(location: location, length: 0)
2027
let lineRange = string.lineRange(for: locationRange)
2128
return manager.characterRange(forGlyphRange: lineRange, actualGlyphRange: nil)
29+
#endif
2230
}
2331

2432
/// Get the line range for a certain text range.
2533
func lineRange(for range: NSRange) -> NSRange {
26-
34+
#if os(watchOS)
35+
return notFoundRange
36+
#else
2737
// Use the location-based logic if range is empty
2838
if range.length == 0 {
2939
return lineRange(at: range.location)
@@ -43,5 +53,6 @@ extension RichTextViewComponent {
4353

4454
// Convert glyph range to character range
4555
return manager.characterRange(forGlyphRange: lineRange, actualGlyphRange: nil)
56+
#endif
4657
}
4758
}

Sources/RichTextKit/Component/RichTextViewComponent.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ public protocol RichTextViewComponent: AnyObject,
5050
/// Whether or not the text view is the first responder.
5151
var isFirstResponder: Bool { get }
5252

53+
#if iOS || macOS || os(tvOS) || os(visionOS)
5354
/// The text view's layout manager, if any.
5455
var layoutManagerWrapper: NSLayoutManager? { get }
5556

57+
/// The text view's text storage, if any.
58+
var textStorageWrapper: NSTextStorage? { get }
59+
#endif
60+
5661
/// The text view's mutable attributed string, if any.
5762
var mutableAttributedString: NSMutableAttributedString? { get }
5863

5964
/// The spacing between the text view's edge and its text.
6065
var textContentInset: CGSize { get set }
6166

62-
/// The text view's text storage, if any.
63-
var textStorageWrapper: NSTextStorage? { get }
64-
6567
/// The text view current typing attributes.
6668
var typingAttributes: RichTextAttributes { get set }
6769

Sources/RichTextKit/_Deprecated/RichTextCoordinator+Deprecated.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if iOS || macOS || os(tvOS) || os(visionOS)
12
import SwiftUI
23

34
public extension RichTextCoordinator {
@@ -7,3 +8,4 @@ public extension RichTextCoordinator {
78
context
89
}
910
}
11+
#endif

Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ final class RichTextViewIntegrationTests: XCTestCase {
6666
// After that we append more text, asserting that this text carries same attributes as the one
6767
// before and we change it.
6868
assertSecondTextPart()
69-
// Finally, we set typingAttributes before we append last text and check if those typingAttributes
69+
// Finally, we set typingAttributes before we append last text and check if those typingAttributes
7070
// are set to our new text.
7171
assertFinalTextPart()
7272
}

0 commit comments

Comments
 (0)