@@ -38,9 +38,12 @@ use crate::{ChUnit, Position};
38
38
/// - `▓▓` = `😃`
39
39
/// - [clip_to_range](crate::UnicodeString::clip_to_range): "e😃"
40
40
#[ derive( Default , Clone , PartialEq , Copy , size_of:: SizeOf ) ]
41
+ // BUG: [ ] introduce scroll adjusted type
41
42
pub struct SelectionRange {
42
- pub start_display_col_index : ChUnit ,
43
- pub end_display_col_index : ChUnit ,
43
+ /// This is not "raw", this is "scroll adjusted".
44
+ pub start_display_col_index_scroll_adjusted : ChUnit ,
45
+ /// This is not "raw", this is "scroll adjusted".
46
+ pub end_display_col_index_scroll_adjusted : ChUnit ,
44
47
}
45
48
46
49
#[ derive( Clone , PartialEq , Copy , Debug ) ]
@@ -54,7 +57,7 @@ impl SelectionRange {
54
57
& self ,
55
58
scroll_offset : Position ,
56
59
) -> ScrollOffsetColLocationInRange {
57
- if self . start_display_col_index >= scroll_offset. col_index {
60
+ if self . start_display_col_index_scroll_adjusted >= scroll_offset. col_index {
58
61
ScrollOffsetColLocationInRange :: Underflow
59
62
} else {
60
63
ScrollOffsetColLocationInRange :: Overflow
@@ -163,9 +166,9 @@ impl SelectionRange {
163
166
/// ```
164
167
/// - [UnicodeString::clip_to_range](crate::UnicodeString::clip_to_range): "ell"
165
168
pub fn locate_column ( & self , caret_display_col_index : ChUnit ) -> CaretLocationInRange {
166
- if caret_display_col_index < self . start_display_col_index {
169
+ if caret_display_col_index < self . start_display_col_index_scroll_adjusted {
167
170
CaretLocationInRange :: Underflow
168
- } else if caret_display_col_index >= self . end_display_col_index {
171
+ } else if caret_display_col_index >= self . end_display_col_index_scroll_adjusted {
169
172
CaretLocationInRange :: Overflow
170
173
} else {
171
174
CaretLocationInRange :: Contained
@@ -174,8 +177,8 @@ impl SelectionRange {
174
177
175
178
pub fn new ( start_display_col_index : ChUnit , end_display_col_index : ChUnit ) -> Self {
176
179
Self {
177
- start_display_col_index,
178
- end_display_col_index,
180
+ start_display_col_index_scroll_adjusted : start_display_col_index,
181
+ end_display_col_index_scroll_adjusted : end_display_col_index,
179
182
}
180
183
}
181
184
@@ -189,7 +192,7 @@ impl SelectionRange {
189
192
/// ```
190
193
pub fn grow_end_by ( & self , amount : ChUnit ) -> Self {
191
194
let mut copy = * self ;
192
- copy. end_display_col_index += amount;
195
+ copy. end_display_col_index_scroll_adjusted += amount;
193
196
copy
194
197
}
195
198
@@ -203,7 +206,7 @@ impl SelectionRange {
203
206
/// ```
204
207
pub fn shrink_end_by ( & self , amount : ChUnit ) -> Self {
205
208
let mut copy = * self ;
206
- copy. end_display_col_index -= amount;
209
+ copy. end_display_col_index_scroll_adjusted -= amount;
207
210
copy
208
211
}
209
212
@@ -217,7 +220,7 @@ impl SelectionRange {
217
220
/// ```
218
221
pub fn grow_start_by ( & self , amount : ChUnit ) -> Self {
219
222
let mut copy = * self ;
220
- copy. start_display_col_index -= amount;
223
+ copy. start_display_col_index_scroll_adjusted -= amount;
221
224
copy
222
225
}
223
226
@@ -231,7 +234,7 @@ impl SelectionRange {
231
234
/// ```
232
235
pub fn shrink_start_by ( & self , amount : ChUnit ) -> Self {
233
236
let mut copy = * self ;
234
- copy. start_display_col_index += amount;
237
+ copy. start_display_col_index_scroll_adjusted += amount;
235
238
copy
236
239
}
237
240
}
@@ -244,8 +247,8 @@ mod range_impl_debug_format {
244
247
write ! (
245
248
f,
246
249
"[start_display_col_index: {start:?}, end_display_col_index: {end:?}]" ,
247
- start = self . start_display_col_index ,
248
- end = self . end_display_col_index
250
+ start = self . start_display_col_index_scroll_adjusted ,
251
+ end = self . end_display_col_index_scroll_adjusted
249
252
)
250
253
}
251
254
}
0 commit comments