editor: Fix selection direction reversal in SelectLargeSyntaxNode with multiple cursors (#51752)

Closes https://github.com/zed-industries/zed/issues/47737

Regressed by https://github.com/zed-industries/zed/pull/27295

Release Notes:

- Fixed an issue where using the `SelectLargeSyntaxNode` action with
multiple cursors could reverse the selection direction for the last
cursor.
This commit is contained in:
Smit Barmase authored and GitHub committed 2026-03-17 12:35:50 +00:00
1 parent 24dc1b13b6
commit 5f6b1739ae
2 files changed
+34 -9

No files matched your search

+6 -6
View File
@@ -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 {
+28 -3
View File
@@ -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,