Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix crash when pasting after copy and trim in visual line mode (#46640)
Dino0ecefe031ee8
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 1e91a871813..3b78bff3914 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -13272,13 +13272,14 @@ impl Editor {trimmed_selections.push(start..end);}+ let is_multiline_trim = trimmed_selections.len() > 1;for trimmed_range in trimmed_selections {if is_first {is_first = false;- } else if !prev_selection_was_entire_line {+ } else if is_multiline_trim || !prev_selection_was_entire_line {text += "\n";}- prev_selection_was_entire_line = is_entire_line;+ prev_selection_was_entire_line = is_entire_line && !is_multiline_trim;let mut len = 0;for chunk in buffer.text_for_range(trimmed_range.start..trimmed_range.end) {text.push_str(chunk);diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 99572e2b5f7..fe0169cabf0 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -7612,6 +7612,25 @@ if is_entire_line {);}+#[gpui::test]+async fn test_copy_trim_line_mode(cx: &mut TestAppContext) {+ init_test(cx, |_| {});++ let mut cx = EditorTestContext::new(cx).await;++ cx.set_state(indoc! {"+ « a+ bˇ»+ "});+ cx.update_editor(|editor, _window, _cx| editor.selections.set_line_mode(true));+ cx.update_editor(|editor, window, cx| editor.copy_and_trim(&CopyAndTrim, window, cx));++ assert_eq!(+ cx.read_from_clipboard().and_then(|item| item.text()),+ Some("a\nb\n".to_string())+ );+}+#[gpui::test]async fn test_paste_multiline(cx: &mut TestAppContext) {init_test(cx, |_| {});