@@ -31,7 +31,7 @@ public extension Range<AbsolutePosition> {
31
31
///
32
32
/// If the intersection is empty, this returns a range starting at offset 0 and having length 0.
33
33
func intersected( _ other: Range < AbsolutePosition > ) -> Range < AbsolutePosition > {
34
- return self . intersecting ( other ) ?? AbsolutePosition ( utf8Offset : 0 ) ..< AbsolutePosition ( utf8Offset : 0 )
34
+ return self . clamped ( to : other )
35
35
}
36
36
}
37
37
@@ -43,20 +43,29 @@ extension Range<AbsolutePosition> {
43
43
self = position..< ( position + length)
44
44
}
45
45
46
+ // Returns `true` if the intersection between this range and `other` is non-empty or if the two ranges are directly
47
+ /// adjacent to each other.
48
+ public func overlapsOrTouches( _ other: Range < AbsolutePosition > ) -> Bool {
49
+ return self . upperBound >= other. lowerBound && self . lowerBound <= other. upperBound
50
+ }
51
+
46
52
/// Returns `true` if the intersection between this range and `other` is non-empty or if the two ranges are directly
47
53
/// adjacent to each other.
54
+ @available ( * , deprecated, renamed: " overlapsOrTouches(_:) " )
48
55
public func intersectsOrTouches( _ other: Range < AbsolutePosition > ) -> Bool {
49
56
return self . upperBound >= other. lowerBound && self . lowerBound <= other. upperBound
50
57
}
51
58
52
59
/// Returns `true` if the intersection between this range and `other` is non-empty.
60
+ @available ( * , deprecated, renamed: " overlaps(_:) " )
53
61
public func intersects( _ other: Range < AbsolutePosition > ) -> Bool {
54
62
return self . upperBound > other. lowerBound && self . lowerBound < other. upperBound
55
63
}
56
64
57
65
/// Returns the range for the overlapping region between two ranges.
58
66
///
59
67
/// If the intersection is empty, this returns `nil`.
68
+ @available ( * , deprecated, message: " Use clamped(to:) instead " )
60
69
public func intersecting( _ other: Range < AbsolutePosition > ) -> Range < AbsolutePosition > ? {
61
70
let lowerBound = Swift . max ( self . lowerBound, other. lowerBound)
62
71
let upperBound = Swift . min ( self . upperBound, other. upperBound)
@@ -114,11 +123,11 @@ public struct IncrementalEdit: Equatable, Sendable {
114
123
}
115
124
116
125
public func intersectsOrTouchesRange( _ other: Range < AbsolutePosition > ) -> Bool {
117
- return self . range. intersectsOrTouches ( other)
126
+ return self . range. overlapsOrTouches ( other)
118
127
}
119
128
120
129
public func intersectsRange( _ other: Range < AbsolutePosition > ) -> Bool {
121
- return self . range. intersects ( other)
130
+ return self . range. overlaps ( other)
122
131
}
123
132
}
124
133
0 commit comments