From 2e883be4b5b9d8e549559775de86e65be5acaf15 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 Jun 2025 10:29:59 -0400 Subject: [PATCH] Add regression test for #11671 (#32250) I can reproduce #11671 on current Nightly but not on `main`; it looks like https://github.com/zed-industries/zed/pull/32204 fixed it. So I'm adding a regression test and closing that issue. Closes #11671 Release Notes: - N/A --- crates/editor/src/editor_tests.rs | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index dc09e1b71a97afa8eef121b8fbfa7c6a705ca761..bbe7212d56fe3433537ae6870a0be73d8a02f2bb 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -22003,3 +22003,53 @@ async fn test_pulling_diagnostics(cx: &mut TestAppContext) { ); ensure_result_id(Some(final_requests.to_string()), cx); } + +#[gpui::test] +async fn test_add_selection_after_moving_with_multiple_cursors(cx: &mut TestAppContext) { + // Regression test for issue #11671 + // Previously, adding a cursor after moving multiple cursors would reset + // the cursor count instead of adding to the existing cursors. + init_test(cx, |_| {}); + let mut cx = EditorTestContext::new(cx).await; + + // Create a simple buffer with cursor at start + cx.set_state(indoc! {" + ˇaaaa + bbbb + cccc + dddd + eeee + ffff + gggg + hhhh"}); + + // Add 2 cursors below (so we have 3 total) + cx.update_editor(|editor, window, cx| { + editor.add_selection_below(&Default::default(), window, cx); + editor.add_selection_below(&Default::default(), window, cx); + }); + + // Verify we have 3 cursors + let initial_count = cx.update_editor(|editor, _, _| editor.selections.count()); + assert_eq!( + initial_count, 3, + "Should have 3 cursors after adding 2 below" + ); + + // Move down one line + cx.update_editor(|editor, window, cx| { + editor.move_down(&MoveDown, window, cx); + }); + + // Add another cursor below + cx.update_editor(|editor, window, cx| { + editor.add_selection_below(&Default::default(), window, cx); + }); + + // Should now have 4 cursors (3 original + 1 new) + let final_count = cx.update_editor(|editor, _, _| editor.selections.count()); + assert_eq!( + final_count, 4, + "Should have 4 cursors after moving and adding another" + ); +}