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.

editor: Show format selections for cursor ranges (#56571)

liam05eea8a321c2
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index a98a998c5f5..9c7a2594950 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -7812,7 +7812,6 @@ impl Editor {
self.selections
.disjoint_anchor_ranges()
- .filter(|range| range.start != range.end)
.flat_map(|range| [range.start, range.end])
.filter_map(|anchor| snapshot.anchor_to_buffer_anchor(anchor))
.filter_map(|(_, buffer_snapshot)| multi_buffer.buffer(buffer_snapshot.remote_id()))
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 1ce8c26a1b0..49eb44ead50 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -14873,6 +14873,24 @@ async fn test_format_selections_action_available_when_range_formatting_is_suppor
assert!(cx.update(|window, cx| { window.is_action_available(&FormatSelections, cx) }));
}
+#[gpui::test]
+async fn test_format_selections_action_available_for_cursor_when_range_formatting_is_supported(
+ cx: &mut TestAppContext,
+) {
+ let (_, editor, cx, _) = setup_range_format_test(cx).await;
+
+ editor.update_in(cx, |editor, window, cx| {
+ editor.set_text("foo\nbar\n", window, cx);
+ editor.change_selections(SelectionEffects::default(), window, cx, |s| {
+ s.select_ranges([Point::new(1, 1)..Point::new(1, 1)]);
+ });
+ });
+
+ refresh_editor_actions(cx);
+
+ assert!(cx.update(|window, cx| { window.is_action_available(&FormatSelections, cx) }));
+}
+
#[gpui::test]
async fn test_format_selections_action_hidden_without_range_formatting_support(
cx: &mut TestAppContext,