Skip to content

Commit d2e2a5b

Browse files
committed
Refactor certain extensions to instead extend KeyPath
1 parent 0efd41c commit d2e2a5b

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ As a result, all parts of the library that handled individual value types have b
1616

1717
### ✨ Features
1818

19-
* `Array` has a new, keypath-based `defaultPickerValues(for:)` value builder.
20-
* `Array` has a new, keypath-based `defaultStepperInterval(for:)` value builder.
21-
* `Image` has a new, keypath-based `richTextParagraphStyleValue(_)` image builder.
2219
* `NSMutableParagraphStyle` has a new `defaultMutable` builder.
2320
* `NSParagraphStyle` has a new `defaultPickerValues(for:)` function.
2421
* `NSParagraphStyle` has a new `defaultStepperSteps(for:)` function.
22+
* `NSParagraphStyle.KeyPath` has a new `defaultIcon` image property.
23+
* `NSParagraphStyle.KeyPath` has a new `defaultPickerValues` property.
24+
* `NSParagraphStyle.KeyPath` has a new `defaultStepperInterval` property.
25+
* `NSTextAlignment` has a new `defaultIcon` image-building property.
26+
* `RichTextContext` has a new `paragraphStyleValueBinding` property.
2527
* `RichTextViewComponent` has a new, keypath-based `richTextParagraphStyleValue(_:)`.
2628
* `RichTextViewComponent` has a new, keypath-based `setRichTextParagraphStyleValue(_:_:)`.
2729
* `RichTextViewComponent` has a new, keypath-based `stepRichTextParagraphStyleValue(_:_:)`.

Sources/RichTextKit/Paragraph/NSParagraphStyle+Picker.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
import SwiftUI
1010

11-
public extension Array {
11+
public extension KeyPath where Root == NSParagraphStyle {
1212

13-
/// Get default picker values for a certain key path.
14-
static func defaultPickerValues<Value>(
15-
for keyPath: KeyPath<NSParagraphStyle, Value>
16-
) -> [Value]? {
17-
switch keyPath {
13+
/// Get default picker values for the key path.
14+
var defaultPickerValues: [Value]? {
15+
switch self {
1816
case \.alignment: NSTextAlignment.defaultPickerValues as? [Value]
1917
case \.allowsDefaultTighteningForTruncation: [true, false] as? [Value]
2018
case \.baseWritingDirection: NSWritingDirection.defaultPickerValues as? [Value]
@@ -42,30 +40,30 @@ public extension NSLineBreakMode {
4240

4341
/// Get the default picker values.
4442
static var defaultPickerValues: [Self] {
45-
[Self.byWordWrapping, .byCharWrapping, .byClipping, .byTruncatingHead, .byTruncatingTail, .byTruncatingMiddle]
43+
[.byWordWrapping, .byCharWrapping, .byClipping, .byTruncatingHead, .byTruncatingTail, .byTruncatingMiddle]
4644
}
4745
}
4846

4947
public extension NSParagraphStyle.LineBreakStrategy {
5048

5149
/// Get the default picker values.
5250
static var defaultPickerValues: [Self] {
53-
[Self.standard, .pushOut, .hangulWordPriority]
51+
[.standard, .pushOut, .hangulWordPriority]
5452
}
5553
}
5654

5755
public extension NSTextAlignment {
5856

5957
/// Get the default picker values.
6058
static var defaultPickerValues: [Self] {
61-
[Self.left, .center, .right, .justified]
59+
[.left, .center, .right, .justified]
6260
}
6361
}
6462

6563
public extension NSWritingDirection {
6664

6765
/// Get the default picker values.
6866
static var defaultPickerValues: [Self] {
69-
[Self.leftToRight, .rightToLeft]
67+
[.leftToRight, .rightToLeft]
7068
}
7169
}

Sources/RichTextKit/Paragraph/NSParagraphStyle+Stepper.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@
88

99
import SwiftUI
1010

11-
public extension Array {
11+
public extension KeyPath where Root == NSParagraphStyle {
1212

13-
/// Get the default stepper interval for a certain pakey path.
14-
static func defaultStepperInterval<Value>(
15-
for keyPath: KeyPath<NSParagraphStyle, Value>
16-
) -> Value? {
17-
switch keyPath {
13+
/// Get the default stepper interval for the key path.
14+
var defaultStepperInterval: Value? {
15+
switch self {
1816
case \.defaultTabInterval: 0.1 as? Value
19-
case \.firstLineHeadIndent: 0.1 as? Value
20-
case \.headIndent: 0.1 as? Value
17+
case \.firstLineHeadIndent: 1 as? Value
18+
case \.headIndent: 1 as? Value
2119
case \.hyphenationFactor: 0.1 as? Value
2220
case \.lineHeightMultiple: 0.1 as? Value
2321
case \.lineSpacing: 0.1 as? Value
2422
case \.maximumLineHeight: 0.1 as? Value
2523
case \.minimumLineHeight: 0.1 as? Value
26-
case \.paragraphSpacing: 0.1 as? Value
27-
case \.paragraphSpacingBefore: 0.1 as? Value
24+
case \.paragraphSpacing: 1 as? Value
25+
case \.paragraphSpacingBefore: 1 as? Value
2826
case \.tailIndent: 0.1 as? Value
2927
default: nil
3028
}

0 commit comments

Comments
 (0)