From 6057d819b0741d7b9ceee2c55b9f1f16979fffb6 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 27 Dec 2021 20:58:01 -0800 Subject: [PATCH] Add a unit test showing panic in move_line_down --- crates/editor/src/editor.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 2f61146cc1e00779dae8cc6ac509115134250446..faee89b545bed6054318ef2291837d3c03bdf314 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1826,6 +1826,7 @@ impl Editor { let next_row_display_end = DisplayPoint::new(display_rows.end, display_map.line_len(display_rows.end)); + let next_row_buffer_end = display_map.next_row_boundary(next_row_display_end).1; let next_row_buffer_end_offset = next_row_buffer_end.to_offset(&buffer); @@ -5168,6 +5169,27 @@ mod tests { }); } + #[gpui::test] + fn test_move_line_up_down_with_blocks(cx: &mut gpui::MutableAppContext) { + let settings = EditorSettings::test(&cx); + let buffer = MultiBuffer::build_simple(&sample_text(10, 5, 'a'), cx); + let (_, editor) = + cx.add_window(Default::default(), |cx| build_editor(buffer, settings, cx)); + editor.update(cx, |editor, cx| { + editor.insert_blocks( + [BlockProperties { + position: Point::new(2, 0), + disposition: BlockDisposition::Below, + height: 1, + render: Arc::new(|_| Empty::new().boxed()), + }], + cx, + ); + editor.select_ranges([Point::new(2, 0)..Point::new(2, 0)], None, cx); + editor.move_line_down(&MoveLineDown, cx); + }); + } + #[gpui::test] fn test_clipboard(cx: &mut gpui::MutableAppContext) { let buffer = MultiBuffer::build_simple("one✅ two three four five six ", cx);