From e96157020966108a7b47e2e48159b60d09d4a907 Mon Sep 17 00:00:00 2001 From: Third-Thing <219055174+Third-Thing@users.noreply.github.com> Date: Fri, 27 Mar 2026 16:09:15 -0700 Subject: [PATCH] fix offset_to_line test failure The test hardcoded expected vline numbers (`4`, `5`) that assumed character `d` at offset 16 would land exactly at a soft wrap boundary at width 36px. The fix discovers the actual wrap boundaries at runtime and asserts the property the test was always meant to verify: at a soft wrap boundary, `Forward` affinity resolves to the next visual line and `Backward` resolves to the previous one. A guard assertion ensures the test fixture still produces at least one soft wrap, so it can't pass vacuously. --- src/views/editor/visual_line.rs | 39 +++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/views/editor/visual_line.rs b/src/views/editor/visual_line.rs index 5632f77b..5ec26ae8 100644 --- a/src/views/editor/visual_line.rs +++ b/src/views/editor/visual_line.rs @@ -2919,18 +2919,39 @@ mod tests { .get(), 1 ); - // starts at 'd'. Tests that cursor affinity works for soft line breaks + // Find a real soft-wrap boundary and verify that affinity selects + // the previous/next visual line at that shared buffer offset. + let wrapped_line = 4; + let wrapped_rvlines: Vec<_> = lines + .iter_rvlines(&text_prov, false, RVLine::new(wrapped_line, 0)) + .take_while(|info| info.rvline.line == wrapped_line) + .map(|info| info.rvline) + .collect(); + assert!( + wrapped_rvlines.len() >= 2, + "test fixture must produce at least one soft wrap" + ); + + let prev = wrapped_rvlines[0]; + let next = wrapped_rvlines[1]; + let boundary = lines.offset_of_rvline(&text_prov, next); + + assert_eq!(text_prov.text().line_of_offset(boundary), wrapped_line); assert_eq!( - lines - .vline_of_offset(&text_prov, 16, CursorAffinity::Forward) - .get(), - 5 + lines.rvline_of_offset(&text_prov, boundary, CursorAffinity::Forward), + next ); assert_eq!( - lines - .vline_of_offset(&text_prov, 16, CursorAffinity::Backward) - .get(), - 4 + lines.rvline_of_offset(&text_prov, boundary, CursorAffinity::Backward), + prev + ); + assert_eq!( + lines.vline_of_offset(&text_prov, boundary, CursorAffinity::Forward), + lines.vline_of_rvline(&text_prov, next) + ); + assert_eq!( + lines.vline_of_offset(&text_prov, boundary, CursorAffinity::Backward), + lines.vline_of_rvline(&text_prov, prev) ); assert_eq!(