editor: Add tests to ensure no horizontal scrolling is possible in soft wrap mode (#36411)

Prior to https://github.com/zed-industries/zed/pull/34564 as well as
https://github.com/zed-industries/zed/pull/26893, we would have cases
where editors would be scrollable even if `soft_wrap` was set to
`editor_width`. This has regressed and improved quite a few times back
and forth. The issue was only within the editor code, the code for the
wrap map was functioning and tested properly.

Hence, this PR adds two tests to the editor rendering code in an effort
to ensure that we maintain the current correct behavior.

Release Notes:

- N/A
This commit is contained in:
Finn Evers 2025-08-18 14:35:54 +02:00 committed by GitHub
parent 1add1d042d
commit 58f7006898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10187,6 +10187,71 @@ mod tests {
use std::num::NonZeroU32;
use util::test::sample_text;
#[gpui::test]
async fn test_soft_wrap_editor_width_auto_height_editor(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(&"a ".to_string().repeat(100), cx);
let mut editor = Editor::new(
EditorMode::AutoHeight {
min_lines: 1,
max_lines: None,
},
buffer,
None,
window,
cx,
);
editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx);
editor
});
let cx = &mut VisualTestContext::from_window(*window, cx);
let editor = window.root(cx).unwrap();
let style = cx.update(|_, cx| editor.read(cx).style().unwrap().clone());
for x in 1..=100 {
let (_, state) = cx.draw(
Default::default(),
size(px(200. + 0.13 * x as f32), px(500.)),
|_, _| EditorElement::new(&editor, style.clone()),
);
assert!(
state.position_map.scroll_max.x == 0.,
"Soft wrapped editor should have no horizontal scrolling!"
);
}
}
#[gpui::test]
async fn test_soft_wrap_editor_width_full_editor(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(&"a ".to_string().repeat(100), cx);
let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx);
editor
});
let cx = &mut VisualTestContext::from_window(*window, cx);
let editor = window.root(cx).unwrap();
let style = cx.update(|_, cx| editor.read(cx).style().unwrap().clone());
for x in 1..=100 {
let (_, state) = cx.draw(
Default::default(),
size(px(200. + 0.13 * x as f32), px(500.)),
|_, _| EditorElement::new(&editor, style.clone()),
);
assert!(
state.position_map.scroll_max.x == 0.,
"Soft wrapped editor should have no horizontal scrolling!"
);
}
}
#[gpui::test]
fn test_shape_line_numbers(cx: &mut TestAppContext) {
init_test(cx, |_| {});