From 05eea8a321c27f913ca8db75d79a6e5bcf7bba64 Mon Sep 17 00:00:00 2001 From: liam Date: Mon, 8 Jun 2026 22:47:01 -0400 Subject: [PATCH] editor: Show format selections for cursor ranges (#56571) Resolves https://github.com/zed-industries/zed/issues/56556 This diff fixes format selections being unavailable when the selection is a cursor range. The action was gated on having at least one non-empty selection, which hid it even when the active formatter supported range formatting. With this change, cursor ranges are included when checking whether the selected buffers support range formatting. This restores the cursor-based `Format Selections` behavior while preserving the existing formatter-capability gate, so the action still stays hidden for formatters that cannot format ranges. https://github.com/user-attachments/assets/fc2ab2b7-1af3-4849-841a-b57a685d748f Release Notes: - Fixed format selections not being available for cursor ranges when the active formatter supports range formatting. Co-authored-by: Christopher Biscardi --- crates/editor/src/editor.rs | 1 - crates/editor/src/editor_tests.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a98a998c5f..9c7a259495 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 1ce8c26a1b..49eb44ead5 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,