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 <chris@christopherbiscardi.com>
This commit is contained in:
liamandChristopher Biscardi authored and GitHub committed 2026-06-09 02:47:01 +00:00
1 parent 0d8a4d4292
commit 05eea8a321
2 files changed
+18 -1

No files matched your search

-1
View File
@@ -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()))
+18
View File
@@ -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,