Skip to content

Commit a8621ce

Browse files
committed
Mini-rework: cleanup.
1 parent 1d914ea commit a8621ce

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Sources/DiffableTextKit/Helpers/Range.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension Range {
3434
//=--------------------------------------=
3535
// MARK: Return
3636
//=--------------------------------------=
37-
from(source, lower: bound, upper: bound)
37+
Self.from(source, lower: bound, upper: bound)
3838
}
3939

4040
@inlinable static func from<T>(_ source: Range<T>,
@@ -54,6 +54,6 @@ extension Range {
5454
//=--------------------------------------=
5555
// MARK: Return
5656
//=--------------------------------------=
57-
return .unchecked((lowerBound, upperBound))
57+
return Self(uncheckedBounds: (lowerBound, upperBound))
5858
}
5959
}

Sources/DiffableTextKit/Models/Changes.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ public struct Changes {
2020

2121
public let snapshot: Snapshot
2222
public var replacement: Snapshot
23-
public var indices: Range<Index>
23+
public var range: Range<Index>
2424

2525
//=------------------------------------------------------------------------=
2626
// MARK: Initializers
2727
//=------------------------------------------------------------------------=
2828

29-
@inlinable init(_ snapshot: Snapshot, with characters: String, at indices: Range<Index>) {
30-
self.snapshot = snapshot; self.indices = indices
29+
@inlinable init(_ snapshot: Snapshot, with characters: String, in range: Range<Index>) {
30+
self.snapshot = snapshot
3131
self.replacement = Snapshot(characters, as: .content)
32+
self.range = range
3233
}
3334

3435
//=------------------------------------------------------------------------=
@@ -37,6 +38,8 @@ public struct Changes {
3738

3839
/// Returns a new snapshot with the proposed change applied to it.
3940
@inlinable public func proposal() -> Snapshot {
40-
var result = snapshot; result.replaceSubrange(indices, with: replacement); return result
41+
var proposal = snapshot
42+
proposal.replaceSubrange(range, with: replacement)
43+
return proposal
4144
}
4245
}

Sources/DiffableTextKit/Models/Context.swift

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

14-
/// Values describing the state of a diffable text view.
14+
/// A set of values describing the state of a diffable text view.
1515
///
16-
/// - Copy-on-write.
16+
/// - Uses copy-on-write.
1717
///
1818
public struct Context<Style: DiffableTextStyle> {
1919
public typealias Commit = DiffableTextKit.Commit<Value>
@@ -222,13 +222,13 @@ public extension Context {
222222
//=--------------------------------------=
223223
// MARK: Values
224224
//=--------------------------------------=
225-
let indices = snapshot.indices(at: range)
225+
let range = snapshot.indices(at: range)
226226
let commit = try style.merge(Changes(
227-
snapshot, with: characters, at: indices))
227+
snapshot, with: characters, in: range))
228228
//=--------------------------------------=
229229
// MARK: Update
230230
//=--------------------------------------=
231-
self.set(selection: indices.upperBound)
231+
self.set(selection: range.upperBound)
232232
self.merge(Self.focused(style, commit))
233233
}
234234

0 commit comments

Comments
 (0)