From 561e7ba2482f6672e9c6c98719435b5cc6a9f357 Mon Sep 17 00:00:00 2001 From: Michal Srutek Date: Tue, 6 Feb 2024 09:31:26 +0100 Subject: [PATCH 1/2] Run SwiftFormat --- .../RichTextKit/Actions/RichTextAction.swift | 22 ++++----- .../RichTextKit/Colors/RichTextColor.swift | 2 +- .../Context/RichTextContext+Colors.swift | 2 +- .../RichTextKit/Context/RichTextContext.swift | 18 ++++---- ...chTextCoordinator+ColorSubscriptions.swift | 2 +- .../RichTextCoordinator+Subscriptions.swift | 6 +-- .../RichTextKit/Data/RichTextDataFormat.swift | 2 +- .../Fonts/RichTextFont+Picker.swift | 2 +- .../RichTextKit/Images/Image+RichText.swift | 2 +- .../RichTextKit/Localization/RTKL10n.swift | 10 ++-- ...chTextCoordinator+SubscriptionsTests.swift | 2 +- ...extCoordinatorIntegrationTests+UIKit.swift | 26 +++++------ .../RichTextViewIntegrationTests+UIKit.swift | 46 +++++++++---------- 13 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Sources/RichTextKit/Actions/RichTextAction.swift b/Sources/RichTextKit/Actions/RichTextAction.swift index 8447d1ef9..36d14cff7 100644 --- a/Sources/RichTextKit/Actions/RichTextAction.swift +++ b/Sources/RichTextKit/Actions/RichTextAction.swift @@ -19,16 +19,16 @@ public enum RichTextAction: Identifiable, Equatable, RichTextLabelValue { /// Copy the currently selected text, if any. case copy - + /// Dismiss any presented software keyboard. case dismissKeyboard - + /// Paste a single image. case pasteImage(RichTextInsertion) - + /// Paste multiple images. case pasteImages(RichTextInsertion<[ImageRepresentable]>) - + /// Paste plain text. case pasteText(RichTextInsertion) @@ -37,25 +37,25 @@ public enum RichTextAction: Identifiable, Equatable, RichTextLabelValue { /// Redo the latest undone change. case redoLatestChange - + /// Select a range. case selectRange(NSRange) - + /// Set the text alignment. case setAlignment(_ alignment: RichTextAlignment) - + /// Set the entire attributed string. case setAttributedString(NSAttributedString) - + // Change background color case setColor(RichTextColor, ColorRepresentable) - + // Highlighted renge case setHighlightedRange(NSRange?) - + // Change highlighting style case setHighlightingStyle(RichTextHighlightingStyle) - + /// Set a certain ``RichTextStyle``. case setStyle(RichTextStyle, Bool) diff --git a/Sources/RichTextKit/Colors/RichTextColor.swift b/Sources/RichTextKit/Colors/RichTextColor.swift index 2219ffb30..370ef9b2a 100644 --- a/Sources/RichTextKit/Colors/RichTextColor.swift +++ b/Sources/RichTextKit/Colors/RichTextColor.swift @@ -67,7 +67,7 @@ public extension RichTextColor { case .undefined: .richTextColorUndefined } } - + /// The localized color title key. var titleKey: RTKL10n { switch self { diff --git a/Sources/RichTextKit/Context/RichTextContext+Colors.swift b/Sources/RichTextKit/Context/RichTextContext+Colors.swift index b98da7a3d..2f0d48c54 100644 --- a/Sources/RichTextKit/Context/RichTextContext+Colors.swift +++ b/Sources/RichTextKit/Context/RichTextContext+Colors.swift @@ -37,7 +37,7 @@ public extension RichTextContext { ) { guard self.color(for: color) != val else { return } userActionPublisher.send(.setColor(color, val)) - + switch color { case .foreground: foregroundColor = val case .background: backgroundColor = val diff --git a/Sources/RichTextKit/Context/RichTextContext.swift b/Sources/RichTextKit/Context/RichTextContext.swift index ff5829647..1364fd0b9 100644 --- a/Sources/RichTextKit/Context/RichTextContext.swift +++ b/Sources/RichTextKit/Context/RichTextContext.swift @@ -12,7 +12,7 @@ import Combine /** This observable context can be used to affect and observe a ``RichTextEditor`` and its content. - + Use ``handle(_:)`` to trigger a change, e.g. to change font, text style, alignment, select a range, etc. You can observe the various published properties to keep your UI updated as @@ -51,27 +51,27 @@ public class RichTextContext: ObservableObject { /// Whether or not the text is currently being edited. @Published public var isEditingText = false - + /// The current text alignment, if any. @Published public var textAlignment: RichTextAlignment = .left - + /// The current font name. @Published public var fontName = "" - + /// The current font size. @Published public var fontSize = CGFloat.standardRichTextFontSize - + /// The currently highlighted range, if any. public var highlightedRange: NSRange? - + /// Use this Publisher to emit any attribute changes to textView. public let userActionPublisher: PassthroughSubject = .init() - + // MARK: - Internal properties - + /// The current background color, if any. @Published public internal(set) var backgroundColor: ColorRepresentable? @@ -95,7 +95,7 @@ public class RichTextContext: ObservableObject { /// Whether or not the indent level can be increased. @Published public internal(set) var canIncreaseIndent = true - + /// The current foreground color, if any. @Published public internal(set) var foregroundColor: ColorRepresentable? diff --git a/Sources/RichTextKit/Coordinator/RichTextCoordinator+ColorSubscriptions.swift b/Sources/RichTextKit/Coordinator/RichTextCoordinator+ColorSubscriptions.swift index 6aee45dc8..b8f7aedf1 100644 --- a/Sources/RichTextKit/Coordinator/RichTextCoordinator+ColorSubscriptions.swift +++ b/Sources/RichTextKit/Coordinator/RichTextCoordinator+ColorSubscriptions.swift @@ -9,7 +9,7 @@ import Foundation extension RichTextCoordinator { - + func setColor(_ color: RichTextColor, to val: ColorRepresentable) { var applyRange: NSRange? = nil if textView.hasSelectedRange { diff --git a/Sources/RichTextKit/Coordinator/RichTextCoordinator+Subscriptions.swift b/Sources/RichTextKit/Coordinator/RichTextCoordinator+Subscriptions.swift index f6de81009..758cd0b01 100644 --- a/Sources/RichTextKit/Coordinator/RichTextCoordinator+Subscriptions.swift +++ b/Sources/RichTextKit/Coordinator/RichTextCoordinator+Subscriptions.swift @@ -16,7 +16,7 @@ extension RichTextCoordinator { self?.handle(action) } .store(in: &cancellables) - + subscribeToAlignment() subscribeToFontName() subscribeToFontSize() @@ -117,7 +117,7 @@ extension RichTextCoordinator { moveCursorToPastedContent: data.moveCursor ) } - + func pasteImages(_ data: RichTextInsertion<[ImageRepresentable]>?) { guard let data = data else { return } textView.pasteImages( @@ -126,7 +126,7 @@ extension RichTextCoordinator { moveCursorToPastedContent: data.moveCursor ) } - + func pasteText(_ data: RichTextInsertion?) { guard let data = data else { return } textView.pasteText( diff --git a/Sources/RichTextKit/Data/RichTextDataFormat.swift b/Sources/RichTextKit/Data/RichTextDataFormat.swift index 9bcf37d03..a10a3ad68 100644 --- a/Sources/RichTextKit/Data/RichTextDataFormat.swift +++ b/Sources/RichTextKit/Data/RichTextDataFormat.swift @@ -20,7 +20,7 @@ import UniformTypeIdentifiers can be used elsewhere. ``archivedData`` uses an `rtk` file extension, as well as a - `UTType.archivedData` uniform type. You can create a custom + `UTType.archivedData` uniform type. You can create a custom ``vendorArchivedData(id:fileExtension:fileFormatText:uniformType:)`` value to specify a custom data format. diff --git a/Sources/RichTextKit/Fonts/RichTextFont+Picker.swift b/Sources/RichTextKit/Fonts/RichTextFont+Picker.swift index a96999870..f7711159f 100644 --- a/Sources/RichTextKit/Fonts/RichTextFont+Picker.swift +++ b/Sources/RichTextKit/Fonts/RichTextFont+Picker.swift @@ -12,7 +12,7 @@ public extension RichTextFont { /** This font picker can be used to pick a font from a list. - + This picker uses ``RichTextFont/PickerFont/all`` as the default fonts. diff --git a/Sources/RichTextKit/Images/Image+RichText.swift b/Sources/RichTextKit/Images/Image+RichText.swift index f9582a11b..4d1eee7e5 100644 --- a/Sources/RichTextKit/Images/Image+RichText.swift +++ b/Sources/RichTextKit/Images/Image+RichText.swift @@ -44,7 +44,7 @@ public extension Image { static let richTextIndentDecrease = symbol("decrease.indent") static let richTextIndentIncrease = symbol("increase.indent") - + static let richTextSelection = symbol("123.rectangle.fill") static let richTextStyleBold = symbol("bold") diff --git a/Sources/RichTextKit/Localization/RTKL10n.swift b/Sources/RichTextKit/Localization/RTKL10n.swift index 4ebbf7d10..12bf641ab 100644 --- a/Sources/RichTextKit/Localization/RTKL10n.swift +++ b/Sources/RichTextKit/Localization/RTKL10n.swift @@ -25,7 +25,7 @@ public enum RTKL10n: String, CaseIterable, Identifiable { underlineColor, strikethroughColor, strokeColor, - + actionCopy, actionDismissKeyboard, actionFontSizeIncrease, @@ -55,17 +55,17 @@ public enum RTKL10n: String, CaseIterable, Identifiable { menuShare, menuShareAs, menuText, - + highlightedRange, highlightingStyle, - + pasteImage, pasteImages, pasteText, selectRange, - + setAttributedString, - + styleBold, styleItalic, styleStrikethrough, diff --git a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift index 637c36c29..7963425c4 100644 --- a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift +++ b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift @@ -119,7 +119,7 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { textContext.userActionPublisher.send(.setStyle(.underlined, true)) XCTAssertTrue(textView.richTextStyles.hasStyle(.underlined)) } - + func testIsStrikeThroughUpdatesTextView() { XCTAssertFalse(textView.richTextStyles.hasStyle(.strikethrough)) textContext.userActionPublisher.send(.setStyle(.strikethrough, true)) diff --git a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift index 86464ac52..b2b4e9d7e 100644 --- a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift +++ b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift @@ -18,18 +18,18 @@ final class RichTextCoordinatorIntegrationTests: XCTestCase { private var textView: RichTextView! private var textContext: RichTextContext! private var coordinator: RichTextCoordinator! - + static let initialAttributedString: NSAttributedString = { let text = NSMutableAttributedString(string: "This is red text") text.addAttributes([.foregroundColor: ColorRepresentable.red], range: text.richTextRange) text.addAttributes([.font: FontRepresentable.systemFont(ofSize: 16)], range: text.richTextRange) return text }() - - + + override func setUp() { super.setUp() - + text = Self.initialAttributedString textBinding = Binding(get: { self.text }, set: { self.text = $0 }) textView = RichTextView(string: text) @@ -41,38 +41,38 @@ final class RichTextCoordinatorIntegrationTests: XCTestCase { textView.selectedRange = NSRange(location: 0, length: 0) textView.setup(with: text, format: .archivedData) } - + override func tearDown() { text = nil textBinding = nil textView = nil textContext = nil coordinator = nil - + super.tearDown() } - + private let firstTypingPart = "String without any attributes" private let imageToPaste = UIGraphicsImageRenderer(size: .init(width: 20, height: 20)).image { rendererContext in UIColor.gray.setFill() rendererContext.fill(CGRect(origin: .zero, size: .init(width: 20, height: 20))) } - + func test_behavior_whenInitialState_keepsConfiguration() { // When starting RichTextEditor we want to check if the font and color is set correctly. textContext.selectRange(.init(location: 0, length: Self.initialAttributedString.length)) - + // Only ArchivedData textView format support images... coordinator.pasteImage(.init(content: imageToPaste, at: textView.richText.length, moveCursor: true)) - + XCTAssertTrue(textView.richText.containsAttachments(in: textView.richTextRange)) - + textView.simulateTyping(of: firstTypingPart) - + textContext.selectRange(NSRange(location: Self.initialAttributedString.length, length: firstTypingPart.count)) XCTAssertEqual(textView.richTextAttributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) XCTAssertEqual(textView.richTextAttributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.red) - + textView.setRichTextStyle(.strikethrough, to: true, at: textView.selectedRange) XCTAssertEqual(textView.richTextAttributes[.strikethroughStyle] as? Int, 1) } diff --git a/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift b/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift index b73872355..d5dcb9ef3 100644 --- a/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift +++ b/Tests/RichTextKitTests/RichTextViewIntegrationTests+UIKit.swift @@ -19,10 +19,10 @@ final class RichTextViewIntegrationTests: XCTestCase { private var textView: RichTextView! private var textContext: RichTextContext! private var coordinator: RichTextCoordinator! - + override func setUp() { super.setUp() - + text = NSAttributedString.empty textBinding = Binding(get: { self.text }, set: { self.text = $0 }) textView = RichTextView(string: text) @@ -34,28 +34,28 @@ final class RichTextViewIntegrationTests: XCTestCase { textView.selectedRange = NSRange(location: 0, length: 1) textView.setRichTextAlignment(.justified) } - + override func tearDown() { text = nil textBinding = nil textView = nil textContext = nil coordinator = nil - + super.tearDown() } - + private let stringWithoutAttributes = "String without any attributes" private let lastStringToAppend = " Last addition..." private let otherStringToAppend = ". And This is some text with other attributes!" - + func test_behavior_forFontStyle() throws { // When starting RichTextEditor we want to check if the font and color is set correctly. textContext.selectRange(.init(location: 0, length: 0)) - + XCTAssertEqual(textView.richTextAttributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) XCTAssertEqual(textView.richTextAttributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.label) - + // First we fill in the empty textView with some text, select it and set bold and italic to it. assertFirstTextPart() // After that we append more text, asserting that this text carries same attributes as the one before @@ -65,59 +65,59 @@ final class RichTextViewIntegrationTests: XCTestCase { // new text. assertFinalTextPart() } - + private func assertFirstTextPart() { textView.simulateTyping(of: stringWithoutAttributes) - + textContext.selectRange(.init(location: 0, length: stringWithoutAttributes.count)) - + XCTAssertEqual(textView.richTextAttributes[.font] as? FontRepresentable, FontRepresentable.systemFont(ofSize: 16)) XCTAssertEqual(textView.richTextAttributes[.foregroundColor] as? ColorRepresentable, ColorRepresentable.label) - + textView.setRichTextStyle(.bold, to: true, at: textView.richTextRange) textView.setRichTextStyle(.italic, to: true, at: textView.richTextRange) - + XCTAssertTrue(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitBold))) XCTAssertTrue(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitItalic))) - + textView.setRichTextStyle(.bold, to: false, at: textView.richTextRange) textView.setRichTextStyle(.italic, to: false, at: textView.richTextRange) XCTAssertFalse(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitBold))) XCTAssertFalse(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitItalic))) } - + private func assertSecondTextPart() { textView.simulateTyping(of: otherStringToAppend) - + textContext.selectRange(NSRange(location: stringWithoutAttributes.count , length: otherStringToAppend.count)) let selectedRange = textView.selectedRange XCTAssertFalse(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitBold))) textView.setRichTextStyle(.strikethrough, to: true, at: selectedRange) - + XCTAssertEqual(textView.richTextAttributes[.strikethroughStyle] as? Int, 1) XCTAssertEqual(textView.richTextAttributes(at: selectedRange)[.strikethroughStyle] as? Int, 1) XCTAssertNil( textView.richTextAttributes(at: NSRange(location: .zero, length: stringWithoutAttributes.count))[.strikethroughStyle] ) - + textContext.selectRange(NSRange(location: 2 , length: .zero)) XCTAssertNil(textView.richTextAttributes[.strikethroughStyle]) } - + private func assertFinalTextPart() { - + textView.setRichTextStyle(.bold, to: true) // Refactor replace into type in tests. // document this... textView.simulateTyping(of: lastStringToAppend) - + XCTAssertTrue(try XCTUnwrap(textView.richTextFont?.fontDescriptor.symbolicTraits.contains(.traitBold))) - + let lastPartLocation = NSRange( location: stringWithoutAttributes.count + otherStringToAppend.count, length: lastStringToAppend.count ) - + let fontForLastString = textView.richTextAttributes(at: lastPartLocation)[.font] as? FontRepresentable XCTAssertTrue(try XCTUnwrap(fontForLastString?.fontDescriptor.symbolicTraits.contains(.traitBold))) } From 061f6fc21870b4b42f06bb6b6fa1093dcafd4dd5 Mon Sep 17 00:00:00 2001 From: Michal Srutek Date: Tue, 6 Feb 2024 09:31:49 +0100 Subject: [PATCH 2/2] Run with consecutiveBlankLines --- .swiftformat | 1 + Sources/RichTextKit/Actions/RichTextAction.swift | 1 - Sources/RichTextKit/Colors/ColorRepresentable.swift | 1 - .../Component/RichTextViewComponent.swift | 3 --- Sources/RichTextKit/Context/RichTextContext.swift | 1 - .../Coordinator/RichTextCoordinator.swift | 7 ------- .../RichTextKit/Fonts/RichTextFont+PickerFont.swift | 4 ---- .../RichTextKit/Format/RichTextFormatSidebar.swift | 1 - .../RichTextKit/Images/RichTextImageAttachment.swift | 2 -- Sources/RichTextKit/RichTextEditor.swift | 5 ----- Sources/RichTextKit/RichTextView_AppKit.swift | 6 ------ Sources/RichTextKit/RichTextView_UIKit.swift | 12 ------------ .../RichTextViewComponent+Deprecated.swift | 5 ----- .../Extensions/String+ParagraphTests.swift | 1 - .../RichTextCoordinator+SubscriptionsTests.swift | 9 --------- .../RichTextCoordinatorIntegrationTests+UIKit.swift | 1 - .../RichTextKitTests/RichTextCoordinatorTests.swift | 1 - Tests/RichTextKitTests/RichTextPresenterTests.swift | 2 -- Tests/RichTextKitTests/RichTextReaderTests.swift | 1 - .../RichTextViewRepresentable+AlignmentTests.swift | 1 - .../RichTextViewRepresentable+AttributesTests.swift | 1 - .../RichTextViewRepresentable+ColorTests.swift | 1 - .../RichTextViewRepresentable+FontSizeTests.swift | 1 - .../RichTextViewRepresentableTests.swift | 1 - .../RichTextKitTests/Styles/RichTextStyleTests.swift | 1 - 25 files changed, 1 insertion(+), 69 deletions(-) diff --git a/.swiftformat b/.swiftformat index 6815357c3..18cad1d0a 100644 --- a/.swiftformat +++ b/.swiftformat @@ -2,5 +2,6 @@ --swiftversion 5.8 # rules +--rules consecutiveBlankLines --rules consecutiveSpaces --rules trailingSpace diff --git a/Sources/RichTextKit/Actions/RichTextAction.swift b/Sources/RichTextKit/Actions/RichTextAction.swift index 36d14cff7..5f0fcbc44 100644 --- a/Sources/RichTextKit/Actions/RichTextAction.swift +++ b/Sources/RichTextKit/Actions/RichTextAction.swift @@ -149,7 +149,6 @@ public extension RichTextAction { } } - // MARK: - Aliases public extension RichTextAction { diff --git a/Sources/RichTextKit/Colors/ColorRepresentable.swift b/Sources/RichTextKit/Colors/ColorRepresentable.swift index 4daa069e1..5a0d9678c 100644 --- a/Sources/RichTextKit/Colors/ColorRepresentable.swift +++ b/Sources/RichTextKit/Colors/ColorRepresentable.swift @@ -16,7 +16,6 @@ import AppKit public typealias ColorRepresentable = NSColor #endif - #if iOS || os(tvOS) || os(watchOS) || os(visionOS) import UIKit diff --git a/Sources/RichTextKit/Component/RichTextViewComponent.swift b/Sources/RichTextKit/Component/RichTextViewComponent.swift index 1afea025e..f51bc73c4 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent.swift @@ -53,7 +53,6 @@ public protocol RichTextViewComponent: AnyObject, /// The text view current typing attributes. var typingAttributes: RichTextAttributes { get set } - // MARK: - Setup /// Setup the view with a text and data format. @@ -62,7 +61,6 @@ public protocol RichTextViewComponent: AnyObject, format: RichTextDataFormat ) - // MARK: - Functions /// Show an alert with a title, message and button text. @@ -87,7 +85,6 @@ public protocol RichTextViewComponent: AnyObject, func undoLatestChange() } - // MARK: - Public Extension public extension RichTextViewComponent { diff --git a/Sources/RichTextKit/Context/RichTextContext.swift b/Sources/RichTextKit/Context/RichTextContext.swift index 1364fd0b9..e30959025 100644 --- a/Sources/RichTextKit/Context/RichTextContext.swift +++ b/Sources/RichTextKit/Context/RichTextContext.swift @@ -45,7 +45,6 @@ public class RichTextContext: ObservableObject { /// The currently selected range, if any. public internal(set) var selectedRange = NSRange() - // MARK: - Public properies /// Whether or not the text is currently being edited. diff --git a/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift b/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift index 8635e425e..68c7899ba 100644 --- a/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift +++ b/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift @@ -48,7 +48,6 @@ open class RichTextCoordinator: NSObject { subscribeToUserActions() } - // MARK: - Properties /// The rich text context to coordinate with. @@ -66,7 +65,6 @@ open class RichTextCoordinator: NSObject { /// This flag is used to avoid delaying context sync. var shouldDelaySyncContextWithTextView = true - // MARK: - Internal Properties /** @@ -81,7 +79,6 @@ open class RichTextCoordinator: NSObject { */ var highlightedRangeOriginalForegroundColor: ColorRepresentable? - #if canImport(UIKit) // MARK: - UITextViewDelegate @@ -103,7 +100,6 @@ open class RichTextCoordinator: NSObject { } #endif - #if canImport(AppKit) && !targetEnvironment(macCatalyst) // MARK: - NSTextViewDelegate @@ -126,7 +122,6 @@ open class RichTextCoordinator: NSObject { #endif } - #if iOS || os(tvOS) || os(visionOS) import UIKit @@ -138,7 +133,6 @@ import AppKit extension RichTextCoordinator: NSTextViewDelegate {} #endif - // MARK: - Public Extensions public extension RichTextCoordinator { @@ -155,7 +149,6 @@ public extension RichTextCoordinator { } } - // MARK: - Internal Extensions extension RichTextCoordinator { diff --git a/Sources/RichTextKit/Fonts/RichTextFont+PickerFont.swift b/Sources/RichTextKit/Fonts/RichTextFont+PickerFont.swift index be82dbb64..0baafea66 100644 --- a/Sources/RichTextKit/Fonts/RichTextFont+PickerFont.swift +++ b/Sources/RichTextKit/Fonts/RichTextFont+PickerFont.swift @@ -59,7 +59,6 @@ public extension RichTextFont { } } - // MARK: - Static Properties public extension RichTextFont.PickerFont { @@ -92,7 +91,6 @@ public extension RichTextFont.PickerFont { } } - // MARK: - Public Properties public extension RichTextFont.PickerFont { @@ -113,7 +111,6 @@ public extension RichTextFont.PickerFont { } } - // MARK: - Collection Extensions public extension Collection where Element == RichTextFont.PickerFont { @@ -135,7 +132,6 @@ public extension Collection where Element == RichTextFont.PickerFont { } } - // MARK: - System Fonts private extension RichTextFont.PickerFont { diff --git a/Sources/RichTextKit/Format/RichTextFormatSidebar.swift b/Sources/RichTextKit/Format/RichTextFormatSidebar.swift index a3a5bd8ad..bb38cd9b6 100644 --- a/Sources/RichTextKit/Format/RichTextFormatSidebar.swift +++ b/Sources/RichTextKit/Format/RichTextFormatSidebar.swift @@ -83,7 +83,6 @@ public struct RichTextFormatSidebar: View { } } - private struct SidebarSection: View { let title: String? diff --git a/Sources/RichTextKit/Images/RichTextImageAttachment.swift b/Sources/RichTextKit/Images/RichTextImageAttachment.swift index d55b712a2..513c04e7a 100644 --- a/Sources/RichTextKit/Images/RichTextImageAttachment.swift +++ b/Sources/RichTextKit/Images/RichTextImageAttachment.swift @@ -147,7 +147,6 @@ open class RichTextImageAttachment: NSTextAttachment { super.init(coder: coder) } - /** Whether or not the attachment supports secure coding. @@ -155,7 +154,6 @@ open class RichTextImageAttachment: NSTextAttachment { */ public override class var supportsSecureCoding: Bool { true } - #if iOS || os(tvOS) || os(visionOS) /** Get or set the attachment image. diff --git a/Sources/RichTextKit/RichTextEditor.swift b/Sources/RichTextKit/RichTextEditor.swift index 7f5c3673e..73aa0f466 100644 --- a/Sources/RichTextKit/RichTextEditor.swift +++ b/Sources/RichTextKit/RichTextEditor.swift @@ -89,7 +89,6 @@ public struct RichTextEditor: ViewRepresentable { } #endif - public func makeCoordinator() -> RichTextCoordinator { RichTextCoordinator( text: text, @@ -98,7 +97,6 @@ public struct RichTextEditor: ViewRepresentable { ) } - #if iOS || os(tvOS) || os(visionOS) public func makeUIView(context: Context) -> some UIView { textView.setup(with: text.wrappedValue, format: format) @@ -122,7 +120,6 @@ public struct RichTextEditor: ViewRepresentable { #endif } - // MARK: RichTextPresenter public extension RichTextEditor { @@ -133,7 +130,6 @@ public extension RichTextEditor { } } - // MARK: RichTextReader public extension RichTextEditor { @@ -144,7 +140,6 @@ public extension RichTextEditor { } } - // MARK: RichTextWriter public extension RichTextEditor { diff --git a/Sources/RichTextKit/RichTextView_AppKit.swift b/Sources/RichTextKit/RichTextView_AppKit.swift index 0d29b28d2..49c4a7b19 100644 --- a/Sources/RichTextKit/RichTextView_AppKit.swift +++ b/Sources/RichTextKit/RichTextView_AppKit.swift @@ -36,7 +36,6 @@ open class RichTextView: NSTextView, RichTextViewComponent { /// The image configuration to use by the rich text view. public var imageConfiguration: RichTextImageConfiguration = .disabled - // MARK: - Overrides /// Paste the current pasteboard content into the view. @@ -93,7 +92,6 @@ open class RichTextView: NSTextView, RichTextViewComponent { .scrollWheel(with: event) } - // MARK: - Setup /** @@ -122,7 +120,6 @@ open class RichTextView: NSTextView, RichTextViewComponent { setContentCompressionResistancePriority(.defaultLow, for: .horizontal) } - // MARK: - Open Functionality /** @@ -172,7 +169,6 @@ open class RichTextView: NSTextView, RichTextViewComponent { } } - // MARK: - Public Extensions public extension RichTextView { @@ -189,7 +185,6 @@ public extension RichTextView { } } - // MARK: - RichTextProvider public extension RichTextView { @@ -206,7 +201,6 @@ public extension RichTextView { } } - // MARK: - RichTextWriter public extension RichTextView { diff --git a/Sources/RichTextKit/RichTextView_UIKit.swift b/Sources/RichTextKit/RichTextView_UIKit.swift index a0b7ee39d..436317e44 100644 --- a/Sources/RichTextKit/RichTextView_UIKit.swift +++ b/Sources/RichTextKit/RichTextView_UIKit.swift @@ -26,7 +26,6 @@ extension RichTextView: UIDropInteractionDelegate {} */ open class RichTextView: UITextView, RichTextViewComponent { - // MARK: - Initializers public convenience init( @@ -45,7 +44,6 @@ open class RichTextView: UITextView, RichTextViewComponent { self.setup(with: string, format: format) } - // MARK: - Properties /// The configuration to use by the rich text view. @@ -74,7 +72,6 @@ open class RichTextView: UITextView, RichTextViewComponent { } } - #if iOS || os(visionOS) /// The image drop interaction to use. @@ -89,14 +86,12 @@ open class RichTextView: UITextView, RichTextViewComponent { #endif - /// Keeps track of the first time a valid frame is set. private var isInitialFrameSetupNeeded = true /// Keeps track of the data format used by the view. private var richTextDataFormat: RichTextDataFormat = .archivedData - // MARK: - Overrides /** @@ -144,7 +139,6 @@ open class RichTextView: UITextView, RichTextViewComponent { } #endif - // MARK: - Setup /** @@ -175,7 +169,6 @@ open class RichTextView: UITextView, RichTextViewComponent { setContentCompressionResistancePriority(.defaultLow, for: .horizontal) } - // MARK: - Open Functionality /// Alert a certain title and message. @@ -245,7 +238,6 @@ open class RichTextView: UITextView, RichTextViewComponent { undoManager?.undo() } - #if iOS || os(visionOS) // MARK: - UIDropInteractionDelegate @@ -296,7 +288,6 @@ open class RichTextView: UITextView, RichTextViewComponent { performTextDrop(with: session, at: range) } - // MARK: - Drop Interaction Support /** @@ -357,7 +348,6 @@ private extension UIDropSession { } #endif - // MARK: - Public Extensions public extension RichTextView { @@ -385,7 +375,6 @@ public extension RichTextView { } } - // MARK: - RichTextProvider public extension RichTextView { @@ -397,7 +386,6 @@ public extension RichTextView { } } - // MARK: - RichTextWriter public extension RichTextView { diff --git a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift index 075eec890..2f6f25ee1 100644 --- a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift +++ b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift @@ -12,7 +12,6 @@ public extension RichTextViewComponent { richTextFont?.pointSize } - @available(*, deprecated, renamed: "currentColor(_:)") var currentBackgroundColor: ColorRepresentable? { currentColor(.background) @@ -145,7 +144,6 @@ public extension RichTextViewComponent { setRichTextAlignment(alignment) } - @available(*, deprecated, message: "richTextColor(_:)") func currentColor(_ color: RichTextColor) -> ColorRepresentable? { richTextColor(color) @@ -158,7 +156,6 @@ public extension RichTextViewComponent { setRichTextAttribute(attribute, to: val) } - @available(*, deprecated, message: "richTextFont") var currentFont: FontRepresentable? { richTextFont @@ -194,7 +191,6 @@ public extension RichTextViewComponent { stepRichTextFontSize(points: points) } - @available(*, deprecated, message: "richTextIndent") var currentIndent: CGFloat? { richTextIndent @@ -207,7 +203,6 @@ public extension RichTextViewComponent { stepRichTextIndent(points: points) } - @available(*, deprecated, message: "richTextStyles") var currentRichTextStyles: [RichTextStyle] { richTextStyles diff --git a/Tests/RichTextKitTests/Extensions/String+ParagraphTests.swift b/Tests/RichTextKitTests/Extensions/String+ParagraphTests.swift index 5b9fab9c6..60c30c7e0 100644 --- a/Tests/RichTextKitTests/Extensions/String+ParagraphTests.swift +++ b/Tests/RichTextKitTests/Extensions/String+ParagraphTests.swift @@ -38,7 +38,6 @@ final class String_ParagraphTests: XCTestCase { XCTAssertEqual(currentResult(for: multi, from: 10), 8) } - func testIndexOfNextParagraphIsCorrectForEmptyString() { XCTAssertEqual(nextResult(for: "", from: 0), 0) XCTAssertEqual(nextResult(for: "", from: 20), 0) diff --git a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift index 7963425c4..4169ce553 100644 --- a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift +++ b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift @@ -48,7 +48,6 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { XCTAssertNotNil(coordinator) } - func testFontNameChangesUpdatesTextView() { XCTAssertNotEqual(textView.richTextFont?.fontName, "Arial") textContext.fontName = "" @@ -62,14 +61,12 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { } } - func testFontSizeChangesUpdatesTextView() { XCTAssertNotEqual(textView.richTextFont?.pointSize, 666) textContext.fontSize = 666 XCTAssertEqual(textView.richTextFont?.pointSize, 666) } - func testFontSizeDecrementUpdatesTextView() { textView.setRichTextFontSize(666) XCTAssertEqual(textView.richTextFont?.pointSize, 666) @@ -77,7 +74,6 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { // XCTAssertEqual(textView.richTextFont?.pointSize, 665) } - func testFontSizeIncrementUpdatesTextView() { textView.setRichTextFontSize(666) XCTAssertEqual(textView.richTextFont?.pointSize, 666) @@ -85,7 +81,6 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { // XCTAssertEqual(textView.richTextFont?.pointSize, 667) TODO: Why is incorrect? } - func testHighlightedRangeUpdatesTextView() { textView.highlightingStyle = RichTextHighlightingStyle( backgroundColor: .yellow, @@ -99,21 +94,18 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { XCTAssertEqual(fore, ColorRepresentable(textView.highlightingStyle.foregroundColor)) } - func testIsBoldUpdatesTextView() { XCTAssertFalse(textView.richTextStyles.hasStyle(.bold)) textContext.userActionPublisher.send(.setStyle(.bold, true)) XCTAssertTrue(textView.richTextStyles.hasStyle(.bold)) } - func testIsItalicUpdatesTextView() { XCTAssertFalse(textView.richTextStyles.hasStyle(.italic)) textContext.userActionPublisher.send(.setStyle(.italic, true)) XCTAssertTrue(textView.richTextStyles.hasStyle(.italic)) } - func testIsUnderlinedUpdatesTextView() { XCTAssertFalse(textView.richTextStyles.hasStyle(.underlined)) textContext.userActionPublisher.send(.setStyle(.underlined, true)) @@ -132,7 +124,6 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { XCTAssertEqual(textView.selectedRange, range) } - func testTextAlignmentUpdatesTextView() { textView.setRichTextAlignment(.left) XCTAssertEqual(textView.richTextAlignment, .left) diff --git a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift index b2b4e9d7e..bfafe1d28 100644 --- a/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift +++ b/Tests/RichTextKitTests/RichTextCoordinatorIntegrationTests+UIKit.swift @@ -26,7 +26,6 @@ final class RichTextCoordinatorIntegrationTests: XCTestCase { return text }() - override func setUp() { super.setUp() diff --git a/Tests/RichTextKitTests/RichTextCoordinatorTests.swift b/Tests/RichTextKitTests/RichTextCoordinatorTests.swift index 15fb1f586..8047f51fa 100644 --- a/Tests/RichTextKitTests/RichTextCoordinatorTests.swift +++ b/Tests/RichTextKitTests/RichTextCoordinatorTests.swift @@ -75,7 +75,6 @@ final class RichTextCoordinatorTests: XCTestCase { #endif } - #if iOS || os(tvOS) func testTextViewDelegateHandlesTextViewDidBeginEditing() { diff --git a/Tests/RichTextKitTests/RichTextPresenterTests.swift b/Tests/RichTextKitTests/RichTextPresenterTests.swift index e54e26797..6a4360f28 100644 --- a/Tests/RichTextKitTests/RichTextPresenterTests.swift +++ b/Tests/RichTextKitTests/RichTextPresenterTests.swift @@ -35,7 +35,6 @@ final class RichTextPresenterTests: XCTestCase { XCTAssertEqual(result, expected) } - func testTextRangeAfterCursorReturnsRangeBeforeSelectionStart() { presenter.selectedRange = NSRange(location: 4, length: 3) let result = presenter.rangeAfterInputCursor @@ -43,7 +42,6 @@ final class RichTextPresenterTests: XCTestCase { XCTAssertEqual(result, expected) } - func testRichTextAtRangeUsesAttributedString() { let range = NSRange(location: 4, length: 3) presenter.selectedRange = range diff --git a/Tests/RichTextKitTests/RichTextReaderTests.swift b/Tests/RichTextKitTests/RichTextReaderTests.swift index 11e17a449..3aff0801b 100644 --- a/Tests/RichTextKitTests/RichTextReaderTests.swift +++ b/Tests/RichTextKitTests/RichTextReaderTests.swift @@ -38,7 +38,6 @@ final class RichTextReaderTests: XCTestCase { XCTAssertEqual(result, "baz") } - func testSafeRangeIsValidForEmptyRangeInEmptyString() { let range = NSRange(location: 0, length: 0) let string = NSAttributedString(string: "") diff --git a/Tests/RichTextKitTests/RichTextViewRepresentable+AlignmentTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentable+AlignmentTests.swift index a39633ea0..6a19a6bb2 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentable+AlignmentTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentable+AlignmentTests.swift @@ -55,7 +55,6 @@ final class RichTextViewComponent_AlignmentTests: XCTestCase { XCTAssertNotEqual(align, alignment) } - func testRichTextAlignmentWorksForSelectedRange() { textView.setSelectedRange(selectedRange) textView.setRichTextAlignment(alignment) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentable+AttributesTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentable+AttributesTests.swift index 41d39c4a6..5b3a58ed5 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentable+AttributesTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentable+AttributesTests.swift @@ -60,7 +60,6 @@ final class RichTextViewComponent_AttributesTests: XCTestCase { assertEqualAttributes(textView.typingAttributes) } - func testTextAttributeValueForKeyIsValidForSelectedRange() { textView.setSelectedRange(selectedRange) textView.setRichTextAttribute(.font, to: font) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentable+ColorTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentable+ColorTests.swift index b4c61f23e..d3873ace6 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentable+ColorTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentable+ColorTests.swift @@ -70,7 +70,6 @@ final class RichTextViewComponent_ColorTests: XCTestCase { assertEqualColor(textView.typingAttributes[.backgroundColor]) } - func testRichTextForegroundColorWorksForSelectedRange() { textView.setSelectedRange(selectedRange) textView.setRichTextColor(.foreground, to: color) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift index 1b46bea8d..ae33f66a6 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift @@ -66,7 +66,6 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase { assertEqualFont(textView.typingAttributes[.font]) } - func testRichTextFontSizeWorksForSelectedRange() { textView.setSelectedRange(selectedRange) textView.setRichTextFontSize(size) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift index 69f04ebec..9b1a707e4 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentableTests.swift @@ -42,7 +42,6 @@ final class RichTextViewComponentTests: XCTestCase { XCTAssertEqual(view.richText.string, "foo bar baz") } - func testSettingUpWithEmptyTextWorks() { let string = NSAttributedString(string: "") view.setup(with: string, format: .rtf) diff --git a/Tests/RichTextKitTests/Styles/RichTextStyleTests.swift b/Tests/RichTextKitTests/Styles/RichTextStyleTests.swift index 163be2d69..254449d36 100644 --- a/Tests/RichTextKitTests/Styles/RichTextStyleTests.swift +++ b/Tests/RichTextKitTests/Styles/RichTextStyleTests.swift @@ -22,7 +22,6 @@ final class RichTextStyleTests: XCTestCase { XCTAssertEqual(icon(for: .underlined), .richTextStyleUnderline) } - #if canImport(UIKit) func traits(for style: RichTextStyle) -> UIFontDescriptor.SymbolicTraits? { style.symbolicTraits