@@ -118,22 +118,27 @@ impl TextRange {
118
118
119
119
/// The range covered by both ranges, if it exists.
120
120
/// If the ranges touch but do not overlap, the output range is empty.
121
- pub fn intersection ( lhs : TextRange , rhs : TextRange ) -> Option < TextRange > {
122
- let start = cmp:: max ( lhs . start ( ) , rhs . start ( ) ) ;
123
- let end = cmp:: min ( lhs . end ( ) , rhs . end ( ) ) ;
121
+ pub fn intersect ( self , other : TextRange ) -> Option < TextRange > {
122
+ let start = cmp:: max ( self . start ( ) , other . start ( ) ) ;
123
+ let end = cmp:: min ( self . end ( ) , other . end ( ) ) ;
124
124
if end < start {
125
125
return None ;
126
126
}
127
127
Some ( TextRange ( start, end) )
128
128
}
129
129
130
- /// The smallest range that completely contains both ranges .
131
- pub fn covering ( lhs : TextRange , rhs : TextRange ) -> TextRange {
132
- let start = cmp:: min ( lhs . start ( ) , rhs . start ( ) ) ;
133
- let end = cmp:: max ( lhs . end ( ) , rhs . end ( ) ) ;
130
+ /// Extends the range to cover `other` as well .
131
+ pub fn cover ( self , other : TextRange ) -> TextRange {
132
+ let start = cmp:: min ( self . start ( ) , other . start ( ) ) ;
133
+ let end = cmp:: max ( self . end ( ) , other . end ( ) ) ;
134
134
TextRange ( start, end)
135
135
}
136
136
137
+ /// Extends the range to cover `other` offsets as well.
138
+ pub fn cover_offset ( self , offset : TextSize ) -> TextRange {
139
+ self . cover ( TextRange :: empty ( offset) )
140
+ }
141
+
137
142
/// Add an offset to this range.
138
143
///
139
144
/// Note that this is not appropriate for changing where a `TextRange` is
0 commit comments