on master help sign in
fix: text_pos_at_screen_coords tests
d62ad8bBlaž Hrastnik
helix-view/src/view.rs+8−4
@@ -260,7 +260,7 @@ impl View {
260
260
261 // If pos is in the middle of a wider grapheme (tab for example)
261 // If pos is in the middle of a wider grapheme (tab for example)
262 // return the starting offset.
262 // return the starting offset.
263− if col + width >= target {
263+ if col + width > target {
264 break;
264 break;
265 }
265 }
266
266
@@ -356,7 +356,7 @@ mod tests {
356
356
357 assert_eq!(
357 assert_eq!(
358 view.text_pos_at_screen_coords(&text, 41, 40 + OFFSET + 1, 4),
358 view.text_pos_at_screen_coords(&text, 41, 40 + OFFSET + 1, 4),
359− Some(5)
359+ Some(4)
360 );
360 );
361
361
362 assert_eq!(
362 assert_eq!(
@@ -384,9 +384,13 @@ mod tests {
384 Some(0)
384 Some(0)
385 );
385 );
386
386
387+ assert_eq!(
388+ view.text_pos_at_screen_coords(&text, 40, 40 + OFFSET + 4, 4),
389+ Some(4)
390+ );
387 assert_eq!(
391 assert_eq!(
388 view.text_pos_at_screen_coords(&text, 40, 40 + OFFSET + 5, 4),
392 view.text_pos_at_screen_coords(&text, 40, 40 + OFFSET + 5, 4),
389− Some(5)
393+ Some(4)
390 );
394 );
391
395
392 assert_eq!(
396 assert_eq!(
@@ -396,7 +400,7 @@ mod tests {
396
400
397 assert_eq!(
401 assert_eq!(
398 view.text_pos_at_screen_coords(&text, 40, 40 + OFFSET + 7, 4),
402 view.text_pos_at_screen_coords(&text, 40, 40 + OFFSET + 7, 4),
399− Some(6)
403+ Some(5)
400 );
404 );
401
405
402 assert_eq!(
406 assert_eq!(