From dcd186166ae75b3b26b18f0f1f4062d9c0f239c4 Mon Sep 17 00:00:00 2001 From: Dominik Bucher Date: Tue, 20 Feb 2024 11:48:27 +0100 Subject: [PATCH 1/2] Add Theme to RichTextEditor init --- Sources/RichTextKit/RichTextEditor.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/RichTextKit/RichTextEditor.swift b/Sources/RichTextKit/RichTextEditor.swift index 895a0d592..729bf7946 100644 --- a/Sources/RichTextKit/RichTextEditor.swift +++ b/Sources/RichTextKit/RichTextEditor.swift @@ -57,11 +57,13 @@ public struct RichTextEditor: ViewRepresentable { text: Binding, context: RichTextContext, config: RichTextView.Configuration = .standard, + theme: RichTextView.Theme = .standard, format: RichTextDataFormat = .archivedData, viewConfiguration: @escaping ViewConfiguration = { _ in } ) { self.text = text self.config = config + self.theme = theme self._context = ObservedObject(wrappedValue: context) self.format = format self.viewConfiguration = viewConfiguration @@ -74,6 +76,7 @@ public struct RichTextEditor: ViewRepresentable { private var text: Binding private let config: RichTextView.Configuration + private let theme: RichTextView.Theme private var format: RichTextDataFormat private var viewConfiguration: ViewConfiguration @@ -101,6 +104,7 @@ public struct RichTextEditor: ViewRepresentable { public func makeUIView(context: Context) -> some UIView { textView.setup(with: text.wrappedValue, format: format) textView.configuration = config + textView.theme = theme viewConfiguration(textView) return textView } @@ -112,6 +116,7 @@ public struct RichTextEditor: ViewRepresentable { public func makeNSView(context: Context) -> some NSView { textView.setup(with: text.wrappedValue, format: format) textView.configuration = config + textView.theme = theme viewConfiguration(textView) return scrollView } From 13c6219c3679ca7ac846b902a02d4a59e7ede21e Mon Sep 17 00:00:00 2001 From: Dominik Bucher Date: Tue, 20 Feb 2024 12:14:39 +0100 Subject: [PATCH 2/2] Fix test --- .../RichTextCoordinatorIntegrationTests+UIKit.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift index 8592b2bcc..8b77548bb 100644 --- a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift +++ b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift @@ -68,14 +68,13 @@ final class RichTextCoordinatorIntegrationTests: XCTestCase { textView.simulateTyping(of: firstTypingPart) - let attributes = textView.richTextAttributes textContext.selectRange(NSRange(location: Self.initialAttributedString.length, length: firstTypingPart.count)) - XCTAssertEqual(attributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) - XCTAssertEqual(attributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.red) + XCTAssertEqual(textView.richTextAttributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) + XCTAssertEqual(textView.richTextAttributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.red) textView.setRichTextStyle(.strikethrough, to: true) - XCTAssertEqual(attributes[.strikethroughStyle] as? Int, 1) + XCTAssertEqual(textView.richTextAttributes[.strikethroughStyle] as? Int, 1) } } #endif