Prefer later bindings in keymap section for display in UI (#23378)
Closes #23015 Release Notes: - Improved which keybindings are selected for display. Now later entries within `bindings` will take precedence. The default keymaps have been updated accordingly.
This commit is contained in:
parent
919703e6a8
commit
aacd80ee4a
11 changed files with 186 additions and 196 deletions
|
@ -19,7 +19,7 @@ impl KeyBinding {
|
|||
/// Returns the highest precedence keybinding for an action. This is the last binding added to
|
||||
/// the keymap. User bindings are added after built-in bindings so that they take precedence.
|
||||
pub fn for_action(action: &dyn Action, cx: &mut WindowContext) -> Option<Self> {
|
||||
let key_binding = cx.bindings_for_action(action).last().cloned()?;
|
||||
let key_binding = cx.bindings_for_action(action).into_iter().rev().next()?;
|
||||
Some(Self::new(key_binding))
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,11 @@ impl KeyBinding {
|
|||
focus: &FocusHandle,
|
||||
cx: &mut WindowContext,
|
||||
) -> Option<Self> {
|
||||
let key_binding = cx.bindings_for_action_in(action, focus).last().cloned()?;
|
||||
let key_binding = cx
|
||||
.bindings_for_action_in(action, focus)
|
||||
.into_iter()
|
||||
.rev()
|
||||
.next()?;
|
||||
Some(Self::new(key_binding))
|
||||
}
|
||||
|
||||
|
@ -198,7 +202,8 @@ impl KeyIcon {
|
|||
|
||||
/// Returns a textual representation of the key binding for the given [`Action`].
|
||||
pub fn text_for_action(action: &dyn Action, cx: &WindowContext) -> Option<String> {
|
||||
let key_binding = cx.bindings_for_action(action).last().cloned()?;
|
||||
let bindings = cx.bindings_for_action(action);
|
||||
let key_binding = bindings.last()?;
|
||||
Some(text_for_key_binding(key_binding, PlatformStyle::platform()))
|
||||
}
|
||||
|
||||
|
@ -209,13 +214,14 @@ pub fn text_for_action_in(
|
|||
focus: &FocusHandle,
|
||||
cx: &mut WindowContext,
|
||||
) -> Option<String> {
|
||||
let key_binding = cx.bindings_for_action_in(action, focus).last().cloned()?;
|
||||
let bindings = cx.bindings_for_action_in(action, focus);
|
||||
let key_binding = bindings.last()?;
|
||||
Some(text_for_key_binding(key_binding, PlatformStyle::platform()))
|
||||
}
|
||||
|
||||
/// Returns a textual representation of the given key binding for the specified platform.
|
||||
pub fn text_for_key_binding(
|
||||
key_binding: gpui::KeyBinding,
|
||||
key_binding: &gpui::KeyBinding,
|
||||
platform_style: PlatformStyle,
|
||||
) -> String {
|
||||
key_binding
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue