You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge swift-6: Generalize Buffer protocols over Range, Content, and Position
Migrate the buffer protocol hierarchy from concrete Foundation types to
fully generic associated types, enabling non-String storage backends
(e.g. ropes, attributed strings) and non-NSRange index schemes.
- Bump to swift-tools-version 6.2 with Swift 6 language mode
- Use SE-0470 isolated conformances for @mainactor Buffer
- Add AsyncBuffer protocol for actor-based conformers
- Promote Range and Location to generic associated types, then derive
Location from Range.Position to make Range the single source of truth
- Extract TextAnalysisCapable as a Buffer refinement for word/line ranges
- Introduce BufferRange protocol with default shifted(by:)/contains(_:)
via AdditiveArithmetic on Position
- Introduce BufferContent protocol; constrain AsyncBuffer.Content to
BufferContent<Range.Position>
- Generalize write signatures from String to Content and relax Undoable's
Base.Content == String constraint
- Generalize BufferAccessFailure factories over any BufferRange
- All 102 tests passing
// This bridging overhead isn't ideal while we operate on `Swift.String` as the `Buffer.Content`. It makes NSRange-based string enumeration easier. As long as `wordRange(for:)` is used to apply commands on the user's behalf, we should be okay in practice even for longer document. Repeated calls to this function, e.g. in loops, could be a disaster, though. See commit d434030e6d9366941c5cc3fa9c6de860afb74710 for an approach that uses two while loops instead.
// Prioritize look-behind over look-ahead iff the location is downstream of a non-whitespace character (non-whitespace to the left of it) and the look-ahead is further away.
// If the result is an empty range, characters adjacent to the location were all `wordBoundary` characters. Then we need to try again with relaxed conditions, skipping over whitespace first. Try forward search, then backward.
117
-
if resultRange.length ==0,
118
-
let closestNonWhitespaceLocation =nonWhitespaceLocation(closestTo: resultRange.location){
0 commit comments