Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix selection direction reversal in `SelectLargeSyntaxNode` with multiple cursors (#51752)
Smit Barmaseb453b6e1c0f6
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 386e51340fd..bff3275ae4d 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -16509,12 +16509,12 @@ impl Editor {.zip(new_selections.last().cloned()).expect("old_selections isn't empty");- // revert selection- let is_selection_reversed = {- let should_newest_selection_be_reversed = last_old.start != last_new.start;- new_selections.last_mut().expect("checked above").reversed =- should_newest_selection_be_reversed;- should_newest_selection_be_reversed+ let is_selection_reversed = if new_selections.len() == 1 {+ let should_be_reversed = last_old.start != last_new.start;+ new_selections.last_mut().expect("checked above").reversed = should_be_reversed;+ should_be_reversed+ } else {+ last_new.reversed};if selected_larger_node {diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 04d3babf20f..f752bb9d21c 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -10057,7 +10057,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut TestAppContext) {use mod1::mod2::{mod3, «mod4ˇ»};fn fn_1«ˇ(param1: bool, param2: &str)» {- let var1 = "«ˇtext»";+ let var1 = "«textˇ»";}"#},cx,@@ -10129,7 +10129,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut TestAppContext) {use mod1::mod2::{mod3, «mod4ˇ»};fn fn_1«ˇ(param1: bool, param2: &str)» {- let var1 = "«ˇtext»";+ let var1 = "«textˇ»";}"#},cx,@@ -10198,7 +10198,32 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut TestAppContext) {use mod1::mod2::«{mod3, mod4}ˇ»;fn fn_1«ˇ(param1: bool, param2: &str)» {- let var1 = "«ˇtext»";+ let var1 = "«textˇ»";+ }+ "#},+ cx,+ );+ });++ // Ensure multiple cursors have consistent direction after expanding+ editor.update_in(cx, |editor, window, cx| {+ editor.unfold_all(&UnfoldAll, window, cx);+ editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {+ s.select_display_ranges([+ DisplayPoint::new(DisplayRow(0), 25)..DisplayPoint::new(DisplayRow(0), 25),+ DisplayPoint::new(DisplayRow(3), 18)..DisplayPoint::new(DisplayRow(3), 18),+ ]);+ });+ editor.select_larger_syntax_node(&SelectLargerSyntaxNode, window, cx);+ });+ editor.update(cx, |editor, cx| {+ assert_text_with_selections(+ editor,+ indoc! {r#"+ use mod1::mod2::{mod3, «mod4ˇ»};++ fn fn_1(param1: bool, param2: &str) {+ let var1 = "«textˇ»";}"#},cx,