From 171be7e009b73062b41ee0f5b8761db543f01119 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Wed, 9 Jul 2025 11:48:35 -0500 Subject: [PATCH] keymap_ui: Render `` for bindings that take arguments where none are provided (#34140) Closes #ISSUE Adds a visual indicator to the `Arguments` column of the keymap table to help distinguish between actions that don't take arguments, and actions that take arguments but none were provided. Currently, the `` indicator is rendered only in the latter case, when no arguments are provided to an action that could take arguments, as the inverse results in almost every row containing the indicator which is quite noisy. Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/settings_ui/src/keybindings.rs | 40 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rs index a0c564479a676be85067cdffbd1b92ee7d0c7f75..3d3421e556eb1a2e5c181824bb40d66ec8ae3026 100644 --- a/crates/settings_ui/src/keybindings.rs +++ b/crates/settings_ui/src/keybindings.rs @@ -31,6 +31,8 @@ use crate::{ ui_components::table::{Table, TableInteractionState}, }; +const NO_ACTION_ARGUMENTS_TEXT: SharedString = SharedString::new_static(""); + actions!( zed, [ @@ -572,14 +574,11 @@ impl KeybindContextString { } impl RenderOnce for KeybindContextString { - fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement { + fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { match self { - KeybindContextString::Global => StyledText::new(KeybindContextString::GLOBAL.clone()) - .with_highlights([( - 0..KeybindContextString::GLOBAL.len(), - gpui::HighlightStyle::color(_cx.theme().colors().text_muted), - )]) - .into_any_element(), + KeybindContextString::Global => { + muted_styled_text(KeybindContextString::GLOBAL.clone(), cx).into_any_element() + } KeybindContextString::Local(name, language) => { SyntaxHighlightedText::new(name, language).into_any_element() } @@ -587,6 +586,14 @@ impl RenderOnce for KeybindContextString { } } +fn muted_styled_text(text: SharedString, cx: &App) -> StyledText { + let len = text.len(); + StyledText::new(text).with_highlights([( + 0..len, + gpui::HighlightStyle::color(cx.theme().colors().text_muted), + )]) +} + impl Item for KeymapEditor { type Event = (); @@ -643,7 +650,7 @@ impl Render for KeymapEditor { .uniform_list( "keymap-editor-table", row_count, - cx.processor(move |this, range: Range, _window, _cx| { + cx.processor(move |this, range: Range, _window, cx| { range .filter_map(|index| { let candidate_id = this.matches.get(index)?.candidate_id; @@ -673,12 +680,17 @@ impl Render for KeymapEditor { binding.keystroke_text.clone().into_any_element(), IntoElement::into_any_element, ); - let action_input = binding - .action_input - .clone() - .map_or(gpui::Empty.into_any_element(), |input| { - input.into_any_element() - }); + let action_input = match binding.action_input.clone() { + Some(input) => input.into_any_element(), + None => { + if binding.action_schema.is_some() { + muted_styled_text(NO_ACTION_ARGUMENTS_TEXT, cx) + .into_any_element() + } else { + gpui::Empty.into_any_element() + } + } + }; let context = binding .context .clone()