Skip to content

Commit e9eddf8

Browse files
committed
Cleanup.
1 parent e510acd commit e9eddf8

File tree

14 files changed

+47
-76
lines changed

14 files changed

+47
-76
lines changed

Sources/DiffableTextKit/Helpers/Carets.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
// MARK: Declaration
1212
//*============================================================================*
1313

14-
/// Up to two carets represented by the bounds in a range.
14+
/// One or two carets, represented by a range.
1515
///
16-
/// An instance with equal bounds represents a single upper caret.
17-
/// This distinction matters for transformations such as map(lower:upper:).
16+
/// An empty range represents a single upper caret.
1817
///
1918
@usableFromInline struct Carets<Caret: Comparable>: Equatable {
2019

Sources/DiffableTextKit/Helpers/Layout.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,9 @@
5353
@inlinable func positions<T>(at indices: Carets<Index>) -> Carets<T.Position> where T: Offset {
5454
indices.map(caret: snapshot.position(at:))
5555
}
56-
}
57-
58-
//=----------------------------------------------------------------------------=
59-
// MARK: Transformations
60-
//=----------------------------------------------------------------------------=
61-
62-
extension Layout {
6356

6457
//=------------------------------------------------------------------------=
65-
// MARK: Snapshot
58+
// MARK: Transformations
6659
//=------------------------------------------------------------------------=
6760

6861
@inlinable mutating func merge(snapshot: Snapshot) {
@@ -79,9 +72,9 @@ extension Layout {
7972
}
8073

8174
//=------------------------------------------------------------------------=
82-
// MARK: Selection
75+
// MARK: Transformations
8376
//=------------------------------------------------------------------------=
84-
77+
8578
@inlinable mutating func merge<T>(selection: Carets<T.Position>, momentums: Bool) where T: Offset {
8679
//=--------------------------------------=
8780
// Values

Sources/DiffableTextKit/Models/Snapshot.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
///
2121
/// Set the anchor to select the caret represented by its index. This may be done
2222
/// on snapshots containing only formatting characters. As an example, a pattern text style
23-
/// that is bound to an empty value may anchor at the first placeholder character.
23+
/// bound to an empty value may anchor at the pattern's first placeholder character.
2424
///
2525
public struct Snapshot: BidirectionalCollection, RangeReplaceableCollection {
2626
@usableFromInline typealias Target = (Index) -> Bool
@@ -301,7 +301,7 @@ extension Snapshot {
301301
//=--------------------------------------=
302302
if let anchor = anchor { return anchor }
303303
//=--------------------------------------=
304-
// Inspect Initial Index
304+
// Inspect The Initial Index
305305
//=--------------------------------------=
306306
if peek(from: index, towards: preference).map(
307307
nonpassthrough(at:)) == true { return index }
@@ -310,21 +310,21 @@ extension Snapshot {
310310
//=--------------------------------------=
311311
let direction = direction ?? preference
312312
//=--------------------------------------=
313-
// Search In Direction
313+
// Search In The Direction
314314
//=--------------------------------------=
315315
if let caret = caret(from: index,
316316
towards: direction,
317317
jumping: direction == preference ? .to : .through,
318318
targeting: nonpassthrough(at:)) { return caret }
319319
//=--------------------------------------=
320-
// Search In Other Direction
320+
// Search In The Other Direction
321321
//=--------------------------------------=
322322
if let caret = caret(from: index,
323323
towards: direction.reversed(),
324324
jumping: Jump.to, // use Jump.to on each direction
325325
targeting: nonpassthrough(at:)) { return caret }
326326
//=--------------------------------------=
327-
// Default To Instance's End Index
327+
// Return End Index
328328
//=--------------------------------------=
329329
return self.endIndex
330330
}
@@ -358,4 +358,18 @@ extension Snapshot {
358358
@inlinable func caret(from index: Index, backwardsThrough target: Target) -> Index? {
359359
indices[..<index].last(where: target)
360360
}
361+
362+
//*========================================================================*
363+
// MARK: Declaration
364+
//*========================================================================*
365+
366+
@usableFromInline enum Jump {
367+
368+
//=--------------------------------------------------------------------=
369+
// MARK: Instances
370+
//=--------------------------------------------------------------------=
371+
372+
case to
373+
case through
374+
}
361375
}

Sources/DiffableTextKit/Support/Collection.swift

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

Sources/DiffableTextKit/Helpers/Jump.swift renamed to Sources/DiffableTextKit/Utilities/Capacity.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
//=----------------------------------------------------------------------------=
99

1010
//*============================================================================*
11-
// MARK: Declaration
11+
// MARK: Extension
1212
//*============================================================================*
1313

14-
@usableFromInline enum Jump {
14+
public extension RangeReplaceableCollection {
1515

1616
//=------------------------------------------------------------------------=
17-
// MARK: Instances
17+
// MARK: Initializers
1818
//=------------------------------------------------------------------------=
1919

20-
case to
21-
case through
20+
@inlinable init(capacity: Int, transform: (inout Self) -> Void) {
21+
self.init(); self.reserveCapacity(capacity); transform(&self)
22+
}
2223
}
File renamed without changes.
File renamed without changes.

Sources/DiffableTextKit/Utilities/Trigger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ extension Optional where Wrapped == Trigger {
5555
//=------------------------------------------------------------------------=
5656

5757
@inlinable public static func += (lhs: inout Self, rhs: Self) {
58-
(rhs != nil && lhs != nil) ? (lhs! += rhs!) : (lhs = rhs)
58+
(lhs != nil && rhs != nil) ? (lhs! += rhs!) : (lhs = rhs)
5959
}
6060
}

Sources/DiffableTextStylesXNumber/Helpers/Lexicon.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public final class Lexicon {
4848

4949
/// Requires that formatter.numberStyle == .none.
5050
@inlinable static func standard(_ formatter: NumberFormatter) -> Lexicon {
51-
assert(formatter.numberStyle == .none); return .init(
51+
assert(formatter.numberStyle == .none); return Self.init(
5252
signs: .standard(formatter),
5353
digits: .standard(formatter),
5454
separators: .standard(formatter))
5555
}
5656

5757
/// Requires that formatter.numberStyle == .none.
5858
@inlinable static func currency(_ formatter: NumberFormatter) -> Lexicon {
59-
assert(formatter.numberStyle == .none); return .init(
59+
assert(formatter.numberStyle == .none); return Self.init(
6060
signs: .currency(formatter),
6161
digits: .currency(formatter),
6262
separators: .currency(formatter))

Sources/DiffableTextStylesXNumber/Helpers/Links.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import Foundation
7878
// MARK: Transformations
7979
//=------------------------------------------------------------------------=
8080

81-
@inlinable mutating func link(_ component: Component, _ character: Character) {
81+
@inlinable mutating func link( _ component: Component, _ character: Character) {
8282
self.components[character] = component
8383
self.characters[component] = character
8484
}

0 commit comments

Comments
 (0)