From 232794a4fe3d675666f678f480e81e20d49ef080 Mon Sep 17 00:00:00 2001 From: Daniel Saidi Date: Wed, 17 Jan 2024 13:45:19 +0100 Subject: [PATCH] Deprecate font name and size and adjust documentation --- Package.swift | 6 ++--- RELEASE_NOTES.md | 3 +++ .../RichTextAttributeReader+Alignment.swift | 2 +- .../RichTextAttributeReader+Font.swift | 9 +------ .../RichTextAttributeReader+Indent.swift | 2 +- .../RichTextAttributeReader+Paragraph.swift | 2 +- .../RichTextAttributeReader+Style.swift | 2 +- .../Attributes/RichTextAttributeReader.swift | 2 +- .../RichTextAttributeWriter+Alignment.swift | 3 --- .../RichTextAttributeWriter+Font.swift | 10 +++---- .../RichTextAttributeWriter+Indent.swift | 4 +-- ...t => RichTextAttributeWriter+Styles.swift} | 2 +- .../RichTextAttributeWriter+Superscript.swift | 2 +- .../Colors/RichTextColorPicker.swift | 2 +- .../RichTextViewComponent+Alignment.swift | 7 +++-- .../RichTextViewComponent+Attributes.swift | 8 +++--- .../RichTextViewComponent+Color.swift | 4 +-- .../RichTextViewComponent+Font.swift | 26 ++++++------------- .../RichTextViewComponent+Images.swift | 1 - .../RichTextViewComponent+Indent.swift | 9 +++---- .../RichTextViewComponent+Paragraph.swift | 25 ++++++++++++++++++ .../RichTextViewComponent+Styles.swift | 4 +-- .../RichTextViewComponent+Superscript.swift | 24 +++++++++++++++++ .../Coordinator/RichTextCoordinator.swift | 4 +-- ... RichTextAttributeReader+Deprecated.swift} | 16 +++++++++++- .../RichTextViewComponent+Deprecated.swift | 15 +++++++++-- ...chTextCoordinator+SubscriptionsTests.swift | 16 ++++++------ .../RichTextCoordinatorTests.swift | 4 +-- ...hTextViewRepresentable+FontSizeTests.swift | 8 +++--- 29 files changed, 137 insertions(+), 85 deletions(-) rename Sources/RichTextKit/Attributes/{RichTextAttributeWriter+Style.swift => RichTextAttributeWriter+Styles.swift} (97%) create mode 100644 Sources/RichTextKit/Component/RichTextViewComponent+Paragraph.swift create mode 100644 Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift rename Sources/RichTextKit/_Deprecated/{RichTextAttributeReader+ColorDeprecated.swift => RichTextAttributeReader+Deprecated.swift} (70%) diff --git a/Package.swift b/Package.swift index ec3ac54ad..19b3a64fb 100644 --- a/Package.swift +++ b/Package.swift @@ -26,7 +26,7 @@ let package = Package( resources: [.process("Resources")], swiftSettings: [ .define("macOS", .when(platforms: [.macOS])), - .define("iOS", .when(platforms: [.iOS, .macCatalyst])), + .define("iOS", .when(platforms: [.iOS, .macCatalyst])) ] ), .testTarget( @@ -34,8 +34,8 @@ let package = Package( dependencies: ["RichTextKit", "MockingKit"], swiftSettings: [ .define("macOS", .when(platforms: [.macOS])), - .define("iOS", .when(platforms: [.iOS, .macCatalyst])), + .define("iOS", .when(platforms: [.iOS, .macCatalyst])) ] - ), + ) ] ) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7b71d695b..7080f6d3d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -20,6 +20,9 @@ This release starts moving types and views that relate to other types into the t * `RichTextActionButtonGroup` has been renamed to `RichTextAction.ButtonGroup`. * `RichTextActionButtonStack` has been renamed to `RichTextAction.ButtonStack`. * `RichTextAlignmentPicker` has been renamed to `RichTextAlignment.Picker`. +* `RichTextArgumentReader` deprecates the font name and size functions. +* `RichTextArgumentWriter` deprecates the font name and size functions. +* `RichTextComponent` deprecates the font name and size functions. diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Alignment.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Alignment.swift index 34c5da489..4bd19c28a 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Alignment.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Alignment.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextAttributeReader { - /// Get the text alignment at a certain range. + /// Get the rich text alignment at a certain range. func richTextAlignment( at range: NSRange ) -> RichTextAlignment? { diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Font.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Font.swift index 0b34a9742..b1273ab75 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Font.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Font.swift @@ -10,17 +10,10 @@ import Foundation public extension RichTextAttributeReader { - /// Get the font at a certain range. + /// Get the rich text font at a certain range. func richTextFont( at range: NSRange ) -> FontRepresentable? { richTextAttribute(.font, at: range) } - - /// Get the font size (in points) at a certain range. - func richTextFontSize( - at range: NSRange - ) -> CGFloat? { - richTextFont(at: range)?.pointSize - } } diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Indent.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Indent.swift index 3730f6f84..37cd60b3c 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Indent.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Indent.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextAttributeReader { - /// Get the text indent in points at a certain range. + /// Get the rich text indent at a certain range. func richTextIndent( at range: NSRange ) -> CGFloat? { diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Paragraph.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Paragraph.swift index 4e92395de..c2181c847 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Paragraph.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Paragraph.swift @@ -18,7 +18,7 @@ import AppKit public extension RichTextAttributeReader { - /// Get the paragraph style at a certain range. + /// Get the rich text paragraph style at a certain range. func richTextParagraphStyle( at range: NSRange ) -> NSMutableParagraphStyle? { diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Style.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Style.swift index ad71eab6c..02d66c31d 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader+Style.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader+Style.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextAttributeReader { - /// Get the text styles at a certain range. + /// Get all rich text styles at a certain range. func richTextStyles( at range: NSRange ) -> [RichTextStyle] { diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeReader.swift b/Sources/RichTextKit/Attributes/RichTextAttributeReader.swift index 1c2f40bfb..a796111c5 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeReader.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeReader.swift @@ -21,7 +21,7 @@ extension NSAttributedString: RichTextAttributeReader {} public extension RichTextAttributeReader { - /// Get a rich text attribute at a certain range. + /// Get a certain rich text attribute at a certain range. func richTextAttribute( _ attribute: RichTextAttribute, at range: NSRange diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Alignment.swift b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Alignment.swift index 9fe9fc546..495665f47 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Alignment.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Alignment.swift @@ -19,9 +19,6 @@ import AppKit public extension RichTextAttributeWriter { /// Set the rich text alignment at a certain range. - /// - /// Unlike some other attributes, this attribute applies - /// to the entire paragraph, not just the selected range. func setRichTextAlignment( _ alignment: RichTextAlignment, at range: NSRange diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Font.swift b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Font.swift index d9f609450..b4c66c273 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Font.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Font.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextAttributeWriter { - /// Set the font at a certain range. + /// Set the rich text font at a certain range. func setRichTextFont( _ font: FontRepresentable, at range: NSRange @@ -18,7 +18,7 @@ public extension RichTextAttributeWriter { setRichTextAttribute(.font, to: font, at: range) } - /// Set the font name at a certain range. + /// Set the rich text font name at a certain range. /// /// This may seem complicated, but so far it is the only /// way that seems to work correctly. @@ -52,7 +52,7 @@ public extension RichTextAttributeWriter { text.endEditing() } - /// Set the font size at a certain range. + /// Set the rich text font size at a certain range. func setRichTextFontSize( _ size: CGFloat, at range: NSRange @@ -70,12 +70,12 @@ public extension RichTextAttributeWriter { text.endEditing() } - /// Step the font size at a certain range. + /// Step the rich text font size at a certain range. func stepRichTextFontSize( points: Int, at range: NSRange ) { - guard let size = richTextFontSize(at: range) else { return } + guard let size = richTextFont(at: range)?.pointSize else { return } let newSize = size + CGFloat(points) setRichTextFontSize(newSize, at: range) } diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Indent.swift b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Indent.swift index 639d44db3..ec81aa506 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Indent.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Indent.swift @@ -51,7 +51,7 @@ public extension RichTextAttributeWriter { return stepRichTextIndent(points: points, atIndex: index) } - /// Step the text indent at a certain index. + /// Step the rich text indent at a certain index. func stepRichTextIndent( points: CGFloat, atIndex index: Int @@ -75,7 +75,7 @@ public extension RichTextAttributeWriter { return attributes } - /// Step the text indent at a certain index. + /// Step the rich text text indent at a certain index. func stepRichTextIndent( points: CGFloat, atIndex index: UInt diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Style.swift b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Styles.swift similarity index 97% rename from Sources/RichTextKit/Attributes/RichTextAttributeWriter+Style.swift rename to Sources/RichTextKit/Attributes/RichTextAttributeWriter+Styles.swift index 27a5741ce..310f28c89 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Style.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Styles.swift @@ -1,5 +1,5 @@ // -// RichTextAttributeWriter+Style.swift +// RichTextAttributeWriter+Styles.swift // RichTextKit // // Created by Daniel Saidi on 2022-05-28. diff --git a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Superscript.swift b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Superscript.swift index 25608bad2..ebb5bbeb5 100644 --- a/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Superscript.swift +++ b/Sources/RichTextKit/Attributes/RichTextAttributeWriter+Superscript.swift @@ -11,7 +11,7 @@ import Foundation public extension RichTextAttributeWriter { - /// Set the superscript level at a certain range. + /// Set the rich text superscript at a certain range. func setRichTextSuperscriptLevel( _ level: Int, at range: NSRange diff --git a/Sources/RichTextKit/Colors/RichTextColorPicker.swift b/Sources/RichTextKit/Colors/RichTextColorPicker.swift index 68f6eeb12..d83c05711 100644 --- a/Sources/RichTextKit/Colors/RichTextColorPicker.swift +++ b/Sources/RichTextKit/Colors/RichTextColorPicker.swift @@ -129,7 +129,7 @@ private extension RichTextColorPicker { } label: { color } - .buttonStyle(ColorButtonStyle( )) + .buttonStyle(ColorButtonStyle()) } var quickPickerDivider: some View { diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Alignment.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Alignment.swift index ee95f48e0..28e7ffd53 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Alignment.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Alignment.swift @@ -18,14 +18,13 @@ import AppKit public extension RichTextViewComponent { - /// Get the current rich text alignment. + /// Get the rich text alignment at current range. var richTextAlignment: RichTextAlignment? { - let attribute: NSMutableParagraphStyle? = richTextAttribute(.paragraphStyle) - guard let style = attribute else { return nil } + guard let style = richTextParagraphStyle else { return nil } return RichTextAlignment(style.alignment) } - /// Set the current text alignment. + /// Set the rich text alignment at current range. func setRichTextAlignment( _ alignment: RichTextAlignment ) { diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Attributes.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Attributes.swift index c6d711e53..906cee263 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Attributes.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Attributes.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextViewComponent { - /// Get all current rich text attributes. + /// Get all rich text attributes at current range. var richTextAttributes: RichTextAttributes { if hasSelectedRange { return richTextAttributes(at: selectedRange) @@ -25,14 +25,14 @@ public extension RichTextViewComponent { #endif } - /// Get a current rich text attribute. + /// Get a certain rich text attribute at current range. func richTextAttribute( _ attribute: RichTextAttribute ) -> Value? { richTextAttributes[attribute] as? Value } - /// Set a current rich text attribute. + /// Set a certain rich text attribute at current range. func setRichTextAttribute( _ attribute: RichTextAttribute, to value: Any @@ -49,7 +49,7 @@ public extension RichTextViewComponent { #endif } - /// Set some current rich text attributes. + /// Set certain attributes at current range. func setRichTextAttributes(_ attributes: RichTextAttributes) { attributes.forEach { attribute, value in setRichTextAttribute(attribute, to: value) diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Color.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Color.swift index 1781294cd..de6babf43 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Color.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Color.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextViewComponent { - /// Get a current rich text color value. + /// Get a certain rich text color at current range. func richTextColor( _ color: RichTextColor ) -> ColorRepresentable? { @@ -18,7 +18,7 @@ public extension RichTextViewComponent { return richTextAttribute(attribute) } - /// Set a current rich text color value. + /// Set a certain rich text color at current range. func setRichTextColor( _ color: RichTextColor, to val: ColorRepresentable diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Font.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Font.swift index 583e26a43..577869679 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Font.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Font.swift @@ -11,29 +11,19 @@ import Foundation public extension RichTextViewComponent { - /// Get the current rich text font. + /// Get the rich text font at current range. var richTextFont: FontRepresentable? { richTextAttributes[.font] as? FontRepresentable ?? typingAttributes[.font] as? FontRepresentable } - /// Get the current rich text font size. - var richTextFontSize: CGFloat? { - richTextFont?.pointSize - } - - /// Get the current rich text font name. - var richTextFontName: String? { - richTextFont?.fontName - } - - /// Set the current rich text font. + /// Set the rich text font at current range. func setRichTextFont(_ font: FontRepresentable) { setRichTextAttribute(.font, to: font) } - /// Set the current rich text font name. + /// Set the rich text font name at current range. func setRichTextFontName(_ name: String) { - if richTextFontName == name { return } + if richTextFont?.fontName == name { return } if hasSelectedRange { setRichTextFontName(name, at: selectedRange) } else { @@ -41,9 +31,9 @@ public extension RichTextViewComponent { } } - /// Set the current rich text font size. + /// Set the rich text font size at current range. func setRichTextFontSize(_ size: CGFloat) { - if size == richTextFontSize { return } + if size == richTextFont?.pointSize { return } #if macOS setRichTextFontSize(size, at: selectedRange) setFontSizeAtCurrentPosition(size) @@ -56,9 +46,9 @@ public extension RichTextViewComponent { #endif } - /// Step the current rich text font size up or down. + /// Step the rich text font size at current range. func stepRichTextFontSize(points: Int) { - let currentSize = richTextFontSize ?? .standardRichTextFontSize + let currentSize = richTextFont?.pointSize ?? .standardRichTextFontSize let newSize = currentSize + CGFloat(points) setRichTextFontSize(newSize) } diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Images.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Images.swift index 9162687c2..851e9d1ab 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Images.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Images.swift @@ -57,7 +57,6 @@ public extension RichTextViewComponent { imageConfiguration.pasteConfiguration } - /// Validate that image drop will be performed. func validateImageInsertion( for config: RichTextImageInsertConfiguration diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Indent.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Indent.swift index f7fdecf71..54de96856 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Indent.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Indent.swift @@ -18,14 +18,12 @@ import AppKit public extension RichTextViewComponent { - /// Get the current rich text indent. + /// Get the rich text indent at current range. var richTextIndent: CGFloat? { - let attribute: NSMutableParagraphStyle? = richTextAttribute(.paragraphStyle) - guard let style = attribute else { return nil } - return style.headIndent + richTextParagraphStyle?.headIndent } - /// Step the current rich text indent. + /// Set the rich text indent at current range. func stepRichTextIndent( points: CGFloat ) { @@ -39,7 +37,6 @@ public extension RichTextViewComponent { private extension RichTextViewComponent { - /// Step the text indent at the current position. func step(points: CGFloat) { guard let style = typingAttributes[.paragraphStyle] as? NSParagraphStyle else { return } guard let mutableStyle = style.mutableCopy() as? NSMutableParagraphStyle else { return } diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Paragraph.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Paragraph.swift new file mode 100644 index 000000000..2ec5a5b4e --- /dev/null +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Paragraph.swift @@ -0,0 +1,25 @@ +// +// RichTextViewComponent+Paragraph.swift +// RichTextKit +// +// Created by Daniel Saidi on 2024-01-17. +// Copyright © 2022-2024 Daniel Saidi. All rights reserved. +// + +import Foundation + +#if canImport(UIKit) +import UIKit +#endif + +#if canImport(AppKit) && !targetEnvironment(macCatalyst) +import AppKit +#endif + +public extension RichTextViewComponent { + + /// Get the rich text paragraph style at current range. + var richTextParagraphStyle: NSMutableParagraphStyle? { + richTextAttribute(.paragraphStyle) + } +} diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Styles.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Styles.swift index 9758b2e59..6708bcaa9 100644 --- a/Sources/RichTextKit/Component/RichTextViewComponent+Styles.swift +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Styles.swift @@ -10,7 +10,7 @@ import Foundation public extension RichTextViewComponent { - /// Get the current rich text styles. + /// Get all rich text styles at current range. var richTextStyles: [RichTextStyle] { let attributes = richTextAttributes let traits = richTextFont?.fontDescriptor.symbolicTraits @@ -20,7 +20,7 @@ public extension RichTextViewComponent { return styles } - /// Set the current value of a certain rich text style. + /// Set a certain rich text style at current range. func setRichTextStyle( _ style: RichTextStyle, to newValue: Bool diff --git a/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift b/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift new file mode 100644 index 000000000..b4acad39b --- /dev/null +++ b/Sources/RichTextKit/Component/RichTextViewComponent+Superscript.swift @@ -0,0 +1,24 @@ +// +// RichTextViewComponent+Color.swift +// RichTextKit +// +// Created by Daniel Saidi on 2022-05-30. +// Copyright © 2022-2023 Daniel Saidi. All rights reserved. +// + +#if os(macOS) +import Foundation + +public extension RichTextViewComponent { + + /// Get the rich text superscript level at current range. + var richTextSuperscriptLevel: Int? { + richTextAttribute(.superscript) + } + + /// Set the rich text superscript level at current range. + func setSuperscript(to val: Int) { + setRichTextAttribute(.superscript, to: val) + } +} +#endif diff --git a/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift b/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift index d5a696962..d85d18644 100644 --- a/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift +++ b/Sources/RichTextKit/Coordinator/RichTextCoordinator.swift @@ -241,13 +241,13 @@ extension RichTextCoordinator { richTextContext.canUndoLatestChange = canUndo } - if let fontName = textView.richTextFontName, + if let fontName = textView.richTextFont?.fontName, !fontName.isEmpty, richTextContext.fontName != fontName { richTextContext.fontName = fontName } - let fontSize = textView.richTextFontSize ?? .standardRichTextFontSize + let fontSize = textView.richTextFont?.pointSize ?? .standardRichTextFontSize if richTextContext.fontSize != fontSize { richTextContext.fontSize = fontSize } diff --git a/Sources/RichTextKit/_Deprecated/RichTextAttributeReader+ColorDeprecated.swift b/Sources/RichTextKit/_Deprecated/RichTextAttributeReader+Deprecated.swift similarity index 70% rename from Sources/RichTextKit/_Deprecated/RichTextAttributeReader+ColorDeprecated.swift rename to Sources/RichTextKit/_Deprecated/RichTextAttributeReader+Deprecated.swift index 8cb41b0c1..6e52221fe 100644 --- a/Sources/RichTextKit/_Deprecated/RichTextAttributeReader+ColorDeprecated.swift +++ b/Sources/RichTextKit/_Deprecated/RichTextAttributeReader+Deprecated.swift @@ -1,6 +1,20 @@ import Foundation -public extension RichTextAttributeWriter { +public extension RichTextAttributeReader { + + @available(*, deprecated, message: "Use richTextFont(at:)?.fontName instead") + func richTextFontName( + at range: NSRange + ) -> String? { + richTextFont(at: range)?.fontName + } + + @available(*, deprecated, message: "Use richTextFont(at:)?.pointSize instead") + func richTextFontSize( + at range: NSRange + ) -> CGFloat? { + richTextFont(at: range)?.pointSize + } @available(*, deprecated, renamed: "richTextColor(_:at:)") func richTextBackgroundColor( diff --git a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift index c62b5f904..2c38e6bc3 100644 --- a/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift +++ b/Sources/RichTextKit/_Deprecated/RichTextViewComponent+Deprecated.swift @@ -1,6 +1,17 @@ import Foundation public extension RichTextViewComponent { + + @available(*, deprecated, message: "Use richTextFont?.fontName instead") + var richTextFontName: String? { + richTextFont?.fontName + } + + @available(*, deprecated, message: "Use richTextFont?.pointSize instead") + var richTextFontSize: CGFloat? { + richTextFont?.pointSize + } + @available(*, deprecated, renamed: "currentColor(_:)") var currentBackgroundColor: ColorRepresentable? { @@ -154,12 +165,12 @@ public extension RichTextViewComponent { richTextFont } - @available(*, deprecated, message: "richTextFontSize") + @available(*, deprecated, message: "Use richTextFont?.pointSize instead") var currentFontSize: CGFloat? { richTextFontSize } - @available(*, deprecated, message: "richTextFontName") + @available(*, deprecated, message: "Use richTextFont?.fontName instead") var currentFontName: String? { richTextFontName } diff --git a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift index f5791ca44..d00838478 100644 --- a/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift +++ b/Tests/RichTextKitTests/RichTextCoordinator+SubscriptionsTests.swift @@ -50,12 +50,12 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { func testFontNameChangesUpdatesTextView() { - XCTAssertNotEqual(textView.richTextFontName, "Arial") + XCTAssertNotEqual(textView.richTextFont?.fontName, "Arial") textContext.fontName = "" eventually { #if iOS || os(tvOS) - XCTAssertEqual(self.textView.richTextFontName, ".SFUI-Regular") + XCTAssertEqual(self.textView.richTextFont?.fontName, ".SFUI-Regular") #elseif macOS XCTAssertEqual(self.textView.richTextFontName, ".AppleSystemUIFont") #endif @@ -64,25 +64,25 @@ final class RichTextCoordinator_SubscriptionsTests: XCTestCase { func testFontSizeChangesUpdatesTextView() { - XCTAssertNotEqual(textView.richTextFontSize, 666) + XCTAssertNotEqual(textView.richTextFont?.pointSize, 666) textContext.fontSize = 666 - XCTAssertEqual(textView.richTextFontSize, 666) + XCTAssertEqual(textView.richTextFont?.pointSize, 666) } func testFontSizeDecrementUpdatesTextView() { textView.setRichTextFontSize(666) - XCTAssertEqual(textView.richTextFontSize, 666) + XCTAssertEqual(textView.richTextFont?.pointSize, 666) textContext.handle(.stepFontSize(points: -1)) - // XCTAssertEqual(textView.richTextFontSize, 665) + // XCTAssertEqual(textView.richTextFont?.pointSize, 665) } func testFontSizeIncrementUpdatesTextView() { textView.setRichTextFontSize(666) - XCTAssertEqual(textView.richTextFontSize, 666) + XCTAssertEqual(textView.richTextFont?.pointSize, 666) textContext.handle(.stepFontSize(points: 1)) - // XCTAssertEqual(textView.richTextFontSize, 667) TODO: Why is incorrect? + // XCTAssertEqual(textView.richTextFont?.pointSize, 667) TODO: Why is incorrect? } diff --git a/Tests/RichTextKitTests/RichTextCoordinatorTests.swift b/Tests/RichTextKitTests/RichTextCoordinatorTests.swift index 2f3587e24..15fb1f586 100644 --- a/Tests/RichTextKitTests/RichTextCoordinatorTests.swift +++ b/Tests/RichTextKitTests/RichTextCoordinatorTests.swift @@ -62,8 +62,8 @@ final class RichTextCoordinatorTests: XCTestCase { func assertIsSyncedWithContext(macOSAlignment: RichTextAlignment = .left) { let styles = view.richTextStyles - XCTAssertEqual(context.fontName, view.richTextFontName) - XCTAssertEqual(context.fontSize, view.richTextFontSize) + XCTAssertEqual(context.fontName, view.richTextFont?.fontName) + XCTAssertEqual(context.fontSize, view.richTextFont?.pointSize) XCTAssertEqual(context.isBold, styles.hasStyle(.bold)) XCTAssertEqual(context.isItalic, styles.hasStyle(.italic)) XCTAssertEqual(context.isUnderlined, styles.hasStyle(.underlined)) diff --git a/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift b/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift index 0b1908cc8..1b46bea8d 100644 --- a/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift +++ b/Tests/RichTextKitTests/RichTextViewRepresentable+FontSizeTests.swift @@ -48,7 +48,7 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase { textView.setSelectedRange(selectedRange) textView.setRichTextFont(font) XCTAssertEqual(textView.richTextFont, font) - XCTAssertEqual(textView.richTextFontName, font.fontName) + XCTAssertEqual(textView.richTextFont?.fontName, font.fontName) assertEqualFont(textView.richTextAttribute(.font)) assertEqualFont(textView.richTextAttributes(at: selectedRange)[.font]) assertEqualFont(textView.typingAttributes[.font]) @@ -59,7 +59,7 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase { textView.setRichTextFont(font) #if iOS || os(tvOS) XCTAssertEqual(textView.richTextFont, font) - XCTAssertEqual(textView.richTextFontName, font.fontName) + XCTAssertEqual(textView.richTextFont?.fontName, font.fontName) assertEqualFont(textView.richTextAttribute(.font)) #endif assertNonEqualFont(textView.richTextAttributes(at: selectedRange)[.font]) @@ -70,7 +70,7 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase { func testRichTextFontSizeWorksForSelectedRange() { textView.setSelectedRange(selectedRange) textView.setRichTextFontSize(size) - XCTAssertEqual(textView.richTextFontSize, size) + XCTAssertEqual(textView.richTextFont?.pointSize, size) assertEqualFontSize(textView.richTextAttribute(.font)) assertEqualFontSize(textView.richTextAttributes(at: selectedRange)[.font]) assertEqualFontSize(textView.typingAttributes[.font], expected: nil) @@ -80,7 +80,7 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase { textView.setSelectedRange(noRange) textView.setRichTextFontSize(size) #if iOS || os(tvOS) - XCTAssertEqual(textView.richTextFontSize, size) + XCTAssertEqual(textView.richTextFont?.pointSize, size) assertEqualFontSize(textView.richTextAttribute(.font)) #endif assertNonEqualFontSize(textView.richTextAttributes(at: selectedRange)[.font])