Skip to content

Commit b652e27

Browse files
committed
Cleanup.
1 parent 07ef4c6 commit b652e27

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

Sources/DiffableTextKit/Models/Offset.swift

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,31 @@ AdditiveArithmetic, ExpressibleByIntegerLiteral {
8989
}
9090

9191
//*============================================================================*
92-
// MARK: * Offset x Int [...]
92+
// MARK: * Offset x Int
9393
//*============================================================================*
9494

9595
public extension Int {
9696

97+
//=------------------------------------------------------------------------=
98+
// MARK: Initializers
99+
//=------------------------------------------------------------------------=
100+
97101
@inlinable @inline(__always)
98102
init<T>(_ offset: Offset<T>) {
99103
self = offset.distance
100104
}
101105
}
102106

103107
//*============================================================================*
104-
// MARK: * Offsets [...]
108+
// MARK: * Offsets
105109
//*============================================================================*
106110

107111
public protocol Offsets<Index>: Collection {
108112

113+
//=------------------------------------------------------------------------=
114+
// MARK: Utilities
115+
//=------------------------------------------------------------------------=
116+
109117
@inlinable @inline(__always) func distance<T>(
110118
from start: Index, to end: Index) -> Offset<T>
111119

@@ -114,11 +122,15 @@ public protocol Offsets<Index>: Collection {
114122
}
115123

116124
//=----------------------------------------------------------------------------=
117-
// MARK: + Details [...]
125+
// MARK: + Details
118126
//=----------------------------------------------------------------------------=
119127

120128
public extension Offsets {
121129

130+
//=------------------------------------------------------------------------=
131+
// MARK: Utilities
132+
//=------------------------------------------------------------------------=
133+
122134
@inlinable @inline(__always) func distance<T>(
123135
from start: Index, to end: Index, as type: T.Type) -> Offset<T> {
124136
distance(from: start, to: end)
@@ -131,6 +143,10 @@ public extension Offsets {
131143
return lower ..< lower + count
132144
}
133145

146+
//=------------------------------------------------------------------------=
147+
// MARK: Utilities
148+
//=------------------------------------------------------------------------=
149+
134150
@inlinable @inline(__always) func index<T>(
135151
from start: Index, move distance: Offset<T>, as type: T.Type) -> Index {
136152
index(from: start, move: distance)
@@ -149,13 +165,17 @@ public extension Offsets {
149165
}
150166

151167
//*============================================================================*
152-
// MARK: * Offsets x String, String.SubSequence [...]
168+
// MARK: * Offsets x String, String.SubSequence
153169
//*============================================================================*
154170

155171
extension String: Offsets { }
156172
extension String.SubSequence: Offsets { }
157173
public extension StringProtocol {
158174

175+
//=------------------------------------------------------------------------=
176+
// MARK: Utilities
177+
//=------------------------------------------------------------------------=
178+
159179
@inlinable @inline(__always) func distance<T>(
160180
from start: Index, to end: Index) -> Offset<T> {
161181
T.distance(from: start, to: end, in: self)
@@ -168,12 +188,16 @@ public extension StringProtocol {
168188
}
169189

170190
//*============================================================================*
171-
// MARK: * Offsets x Snapshot [...]
191+
// MARK: * Offsets x Snapshot
172192
//*============================================================================*
173193

174194
extension Snapshot: Offsets { }
175195
public extension Snapshot {
176196

197+
//=------------------------------------------------------------------------=
198+
// MARK: Utilities
199+
//=------------------------------------------------------------------------=
200+
177201
@inlinable @inline(__always) func distance<T>(
178202
from start: Index, to end: Index) -> Offset<T> {
179203
T.distance(from: start, to: end, in: self)
@@ -186,11 +210,15 @@ public extension Snapshot {
186210
}
187211

188212
//*============================================================================*
189-
// MARK: * Encoding [...]
213+
// MARK: * Encoding
190214
//*============================================================================*
191215

192216
public protocol Encoding {
193217

218+
//=------------------------------------------------------------------------=
219+
// MARK: Utilities
220+
//=------------------------------------------------------------------------=
221+
194222
@inlinable @inline(__always) static func distance(
195223
from start: String.Index, to end: String.Index,
196224
in collection: some StringProtocol) -> Offset<Self>
@@ -199,6 +227,10 @@ public protocol Encoding {
199227
from start: String.Index, move distance: Offset<Self>,
200228
in collection: some StringProtocol) -> String.Index
201229

230+
//=------------------------------------------------------------------------=
231+
// MARK: Utilities
232+
//=------------------------------------------------------------------------=
233+
202234
@inlinable @inline(__always) static func distance(
203235
from start: Snapshot.Index, to end: Snapshot.Index,
204236
in collection: Snapshot) -> Offset<Self>
@@ -209,11 +241,15 @@ public protocol Encoding {
209241
}
210242

211243
//=----------------------------------------------------------------------------=
212-
// MARK: + Details [...]
244+
// MARK: + Details
213245
//=----------------------------------------------------------------------------=
214246

215247
public extension Encoding {
216248

249+
//=------------------------------------------------------------------------=
250+
// MARK: Utilities
251+
//=------------------------------------------------------------------------=
252+
217253
@inlinable @inline(__always) static func distance(
218254
from start: Snapshot.Index, to end: Snapshot.Index,
219255
in collection: Snapshot) -> Offset<Self> {
@@ -235,12 +271,16 @@ public extension Encoding {
235271
}
236272

237273
//*============================================================================*
238-
// MARK: * Encoding x Character [...]
274+
// MARK: * Encoding x Character
239275
//*============================================================================*
240276

241277
extension Character: Encoding { }
242278
public extension Character {
243279

280+
//=------------------------------------------------------------------------=
281+
// MARK: Utilities
282+
//=------------------------------------------------------------------------=
283+
244284
@inlinable @inline(__always) static func distance(
245285
from start: String.Index, to end: String.Index,
246286
in collection: some StringProtocol) -> Offset<Self> {
@@ -253,6 +293,10 @@ public extension Character {
253293
collection.index(start, offsetBy: Int(distance))
254294
}
255295

296+
//=------------------------------------------------------------------------=
297+
// MARK: Utilities
298+
//=------------------------------------------------------------------------=
299+
256300
@inlinable @inline(__always) static func distance(
257301
from start: Snapshot.Index, to end: Snapshot.Index,
258302
in collection: Snapshot) -> Offset<Self> {
@@ -267,12 +311,16 @@ public extension Character {
267311
}
268312

269313
//*============================================================================*
270-
// MARK: * Encoding x Unicode.Scalar [...]
314+
// MARK: * Encoding x Unicode.Scalar
271315
//*============================================================================*
272316

273317
extension Unicode.Scalar: Encoding { }
274318
public extension Unicode.Scalar {
275319

320+
//=------------------------------------------------------------------------=
321+
// MARK: Utilities
322+
//=------------------------------------------------------------------------=
323+
276324
@inlinable @inline(__always) static func distance(
277325
from start: String.Index, to end: String.Index,
278326
in collection: some StringProtocol) -> Offset<Self> {
@@ -287,12 +335,16 @@ public extension Unicode.Scalar {
287335
}
288336

289337
//*============================================================================*
290-
// MARK: * Encoding x UTF16 [...]
338+
// MARK: * Encoding x UTF16
291339
//*============================================================================*
292340

293341
extension UTF16: Encoding { }
294342
public extension UTF16 {
295343

344+
//=------------------------------------------------------------------------=
345+
// MARK: Utilities
346+
//=------------------------------------------------------------------------=
347+
296348
@inlinable @inline(__always) static func distance(
297349
from start: String.Index, to end: String.Index,
298350
in collection: some StringProtocol) -> Offset<Self> {
@@ -307,12 +359,16 @@ public extension UTF16 {
307359
}
308360

309361
//*============================================================================*
310-
// MARK: * Encoding x UTF8 [...]
362+
// MARK: * Encoding x UTF8
311363
//*============================================================================*
312364

313365
extension UTF8: Encoding { }
314366
public extension UTF8 {
315367

368+
//=------------------------------------------------------------------------=
369+
// MARK: Utilities
370+
//=------------------------------------------------------------------------=
371+
316372
@inlinable @inline(__always) static func distance(
317373
from start: String.Index, to end: String.Index,
318374
in collection: some StringProtocol) -> Offset<Self> {

Sources/DiffableTextKit/Styles/Prefix.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
8686
let start = snapshot.endIndex
8787
snapshot.append(contentsOf: base)
8888
//=--------------------------------------=
89-
// Base x Some x Selection
89+
// Base x Selection
9090
//=--------------------------------------=
9191
guard let selection = base.selection else { return }
9292
let min = selection .lower.attribute

0 commit comments

Comments
 (0)