Skip to content

Commit 679056c

Browse files
committed
Make all tests work and fix all deprecation warnings
1 parent f0f0907 commit 679056c

File tree

6 files changed

+32
-136
lines changed

6 files changed

+32
-136
lines changed

Sources/RichTextKit/Format/RichTextFormat+Sidebar.swift

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,30 @@ import SwiftUI
1111

1212
public extension RichTextFormat {
1313

14-
/**
15-
This sidebar view provides various text format options, and
16-
is meant to be used on macOS, in a trailing sidebar.
17-
18-
You can configure and style the view by applying its config
19-
and style view modifiers to your view hierarchy:
20-
21-
```swift
22-
VStack {
23-
...
24-
}
25-
.richTextFormatSidebarStyle(...)
26-
.richTextFormatSidebarConfig(...)
27-
```
28-
29-
> Note: The sidebar is currently designed for macOS, but it
30-
should also be made to look good on iPadOS in landscape, to
31-
let us use it instead of the ``RichTextFormat/Sheet``.
32-
*/
14+
/// This view has various format options and is meant to
15+
/// be used on macOS, in a trailing sidebar.
16+
///
17+
/// You can configure and style the view by applying its
18+
/// config & style view modifiers to your view hierarchy:
19+
///
20+
/// ```swift
21+
/// VStack {
22+
/// ...
23+
/// }
24+
/// .richTextFormatSidebarStyle(...)
25+
/// .richTextFormatSidebarConfig(...)
26+
/// ```
27+
///
28+
/// > Note: This sidebar is currently designed for macOS,
29+
/// but it should also be made to look good on iPadOS in
30+
/// landscape, to let us use this sidebar instead of the
31+
/// ``RichTextFormat/Sheet``.
3332
struct Sidebar: RichTextFormatToolbarBase {
3433

35-
/**
36-
Create a rich text format sheet.
37-
38-
- Parameters:
39-
- context: The context to apply changes to.
40-
*/
34+
/// Create a rich text format sheet.
35+
///
36+
/// - Parameters:
37+
/// - context: The context to apply changes to.
4138
public init(
4239
context: RichTextContext
4340
) {

Sources/RichTextKit/_Essential/RichTextContext.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ public class RichTextContext: ObservableObject {
120120

121121
@available(*, deprecated, message: "Use paragraphStyle instead.")
122122
public var textAlignment: RichTextAlignment {
123-
get { .init(textAlignmentInternal) }
124-
set { textAlignmentInternal = newValue.nativeAlignment }
123+
get { .init(paragraphStyleValue(for: \.alignment)) }
124+
set { paragraphStyle[keyPath: \.alignment] = newValue.nativeAlignment }
125125
}
126-
127-
@Published public var textAlignmentInternal: NSTextAlignment = .left
128126
}
129127

130128
public extension RichTextContext {

Sources/RichTextKit/_Foundation/RichTextCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extension RichTextCoordinator {
179179
sync(&context.fontName, with: font.fontName)
180180
sync(&context.fontSize, with: font.pointSize)
181181
sync(&context.isEditingText, with: textView.isFirstResponder)
182-
sync(&context.textAlignmentInternal, with: (textView.richTextParagraphStyleValue(\.alignment) ?? .left))
182+
sync(&context.paragraphStyle, with: textView.richTextParagraphStyle ?? .defaultMutable)
183183

184184
RichTextColor.allCases.forEach {
185185
if let color = textView.richTextColor($0) {

Tests/RichTextKitTests/RichTextViewRepresentable+AlignmentTests.swift

Lines changed: 0 additions & 97 deletions
This file was deleted.

Tests/RichTextKitTests/_Foundation/RichTextCoordinator+SubscriptionsTests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase {
124124
XCTAssertEqual(textView.selectedRange, range)
125125
}
126126

127-
func testTextAlignmentUpdatesTextView() {
128-
textView.setRichTextAlignment(.left)
129-
XCTAssertEqual(textView.richTextAlignment, .left)
130-
textContext.textAlignment = .right
131-
XCTAssertEqual(textView.richTextAlignment, .right)
127+
func testSettingParagraphStyleValueUpdatesTheParagraphStyle() {
128+
textView.setRichTextParagraphStyleValue(\.alignment, .left)
129+
XCTAssertEqual(textView.richTextParagraphStyleValue(\.alignment), .left)
132130
}
133131
}
134132
#endif

Tests/RichTextKitTests/_Foundation/RichTextCoordinatorTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class RichTextCoordinatorTests: XCTestCase {
3232
richTextContext: context)
3333
coordinator.shouldDelaySyncContextWithTextView = false
3434
view.selectedRange = NSRange(location: 0, length: 1)
35-
view.setRichTextAlignment(.justified)
35+
view.setRichTextParagraphStyleValue(\.alignment, .justified)
3636
}
3737

3838
override func tearDown() {
@@ -83,14 +83,14 @@ final class RichTextCoordinatorTests: XCTestCase {
8383
XCTAssertEqual(context.fontSize, view.richTextFont?.pointSize)
8484
XCTAssertEqual(context.isEditingText, view.isFirstResponder)
8585
// XCTAssertEqual(context.lineSpacing, view.richTextLineSpacing) TODO: Not done yet
86-
XCTAssertEqual(context.textAlignment, view.richTextAlignment)
86+
XCTAssertEqual(context.paragraphStyleValue(for: \.alignment), view.richTextParagraphStyleValue(\.alignment))
8787
}
8888

8989
func testChangingOtherViewPropertiesUpdatesContextAfterExplicitUpdate() {
9090

9191
}
9292

93-
func assertIsSyncedWithContext(macOSAlignment: RichTextAlignment = .left) {
93+
func assertIsSyncedWithContext(macOSAlignment: NSTextAlignment = .left) {
9494
let styles = view.richTextStyles
9595
XCTAssertEqual(context.fontName, view.richTextFont?.fontName)
9696
XCTAssertEqual(context.fontSize, view.richTextFont?.pointSize)
@@ -99,7 +99,7 @@ final class RichTextCoordinatorTests: XCTestCase {
9999
XCTAssertEqual(context.styles[.underlined], styles.hasStyle(.underlined))
100100
XCTAssertEqual(context.selectedRange, view.selectedRange)
101101
#if iOS || os(tvOS)
102-
XCTAssertEqual(context.textAlignment, view.richTextAlignment)
102+
XCTAssertEqual(context.paragraphStyleValue(for: \.alignment), view.richTextParagraphStyleValue(\.alignment))
103103
#elseif macOS
104104
XCTAssertEqual(context.textAlignment, macOSAlignment)
105105
#endif

0 commit comments

Comments
 (0)