Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Unify selection directions when performing `editor: select all selections` (#23993)

Joseph T. Lyons4c8b5ea4f726
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index dff1c55f156..491b9c44d3f 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -8827,6 +8827,12 @@ impl Editor {
}
}
+ let reversed = self.selections.oldest::<usize>(cx).reversed;
+
+ for selection in new_selections.iter_mut() {
+ selection.reversed = reversed;
+ }
+
select_next_state.done = true;
self.unfold_ranges(
&new_selections
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index c5336e10f6c..bbf631c671c 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -5236,11 +5236,27 @@ async fn test_select_all_matches(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
+
+ // Test caret-only selections
cx.set_state("abc\nˇabc abc\ndefabc\nabc");
cx.update_editor(|e, window, cx| e.select_all_matches(&SelectAllMatches, window, cx))
.unwrap();
cx.assert_editor_state("«abcˇ»\n«abcˇ» «abcˇ»\ndefabc\n«abcˇ»");
+
+ // Test left-to-right selections
+ cx.set_state("abc\n«abcˇ»\nabc");
+
+ cx.update_editor(|e, window, cx| e.select_all_matches(&SelectAllMatches, window, cx))
+ .unwrap();
+ cx.assert_editor_state("«abcˇ»\n«abcˇ»\n«abcˇ»");
+
+ // Test right-to-left selections
+ cx.set_state("abc\n«ˇabc»\nabc");
+
+ cx.update_editor(|e, window, cx| e.select_all_matches(&SelectAllMatches, window, cx))
+ .unwrap();
+ cx.assert_editor_state("«ˇabc»\n«ˇabc»\n«ˇabc»");
}
#[gpui::test]