diff --git a/crates/ui/src/components/context_menu.rs b/crates/ui/src/components/context_menu.rs index df7de5b2e8..18fea79f16 100644 --- a/crates/ui/src/components/context_menu.rs +++ b/crates/ui/src/components/context_menu.rs @@ -752,7 +752,7 @@ impl ContextMenu { KeyBinding::for_action(&**action, window, cx) }) .map(|binding| { - div().ml_4().child(binding).when( + div().ml_4().child(binding.disabled(*disabled)).when( *disabled && documentation_aside_callback.is_some(), |parent| parent.invisible(), ) diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index 63b63da45f..5f99b14298 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -20,6 +20,9 @@ pub struct KeyBinding { /// Determines whether the keybinding is meant for vim mode. vim_mode: bool, + + /// Indicates whether the keybinding is currently disabled. + disabled: bool, } struct VimStyle(bool); @@ -64,6 +67,7 @@ impl KeyBinding { platform_style: PlatformStyle::platform(), size: None, vim_mode: KeyBinding::is_vim_mode(cx), + disabled: false, } } @@ -79,6 +83,13 @@ impl KeyBinding { self } + /// Sets whether this keybinding is currently disabled. + /// Disabled keybinds will be rendered in a dimmed state. + pub fn disabled(mut self, disabled: bool) -> Self { + self.disabled = disabled; + self + } + pub fn vim_mode(mut self, enabled: bool) -> Self { self.vim_mode = enabled; self @@ -98,6 +109,7 @@ impl KeyBinding { impl RenderOnce for KeyBinding { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { + let color = self.disabled.then_some(Color::Disabled); let use_text = self.vim_mode || matches!( self.platform_style, @@ -127,7 +139,7 @@ impl RenderOnce for KeyBinding { el.child( Key::new( keystroke_text(&keystroke, self.platform_style, self.vim_mode), - None, + color, ) .size(self.size), ) @@ -136,11 +148,11 @@ impl RenderOnce for KeyBinding { el.children(render_modifiers( &keystroke.modifiers, self.platform_style, - None, + color, self.size, true, )) - .map(|el| el.child(self.render_key(&keystroke, None))) + .map(|el| el.child(self.render_key(&keystroke, color))) }) })) }