Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Add tests to ensure no horizontal scrolling is possible in soft wrap mode (#36411)
Finn Evers58f7006898d2
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex c15ff3e5094..e56ac45fab8 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -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, |_| {});