keymap_ui: Dim keybinds that are overridden by other keybinds (#34952)

This change dims rows in the keymap editor for which the corresponding
keybind is overridden by other keybinds coming from higher priority
sources.

Release Notes:

- N/A
This commit is contained in:
Finn Evers 2025-07-23 18:03:04 +02:00 committed by GitHub
parent 326fe05b33
commit 8713c556d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 602 additions and 347 deletions

View file

@ -959,19 +959,21 @@ impl<'a> KeybindUpdateTarget<'a> {
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum KeybindSource {
User,
Default,
Base,
Vim,
Base,
#[default]
Default,
Unknown,
}
impl KeybindSource {
const BASE: KeyBindingMetaIndex = KeyBindingMetaIndex(0);
const DEFAULT: KeyBindingMetaIndex = KeyBindingMetaIndex(1);
const VIM: KeyBindingMetaIndex = KeyBindingMetaIndex(2);
const USER: KeyBindingMetaIndex = KeyBindingMetaIndex(3);
const BASE: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::Base as u32);
const DEFAULT: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::Default as u32);
const VIM: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::Vim as u32);
const USER: KeyBindingMetaIndex = KeyBindingMetaIndex(KeybindSource::User as u32);
pub fn name(&self) -> &'static str {
match self {
@ -979,6 +981,7 @@ impl KeybindSource {
KeybindSource::Default => "Default",
KeybindSource::Base => "Base",
KeybindSource::Vim => "Vim",
KeybindSource::Unknown => "Unknown",
}
}
@ -988,21 +991,18 @@ impl KeybindSource {
KeybindSource::Default => Self::DEFAULT,
KeybindSource::Base => Self::BASE,
KeybindSource::Vim => Self::VIM,
KeybindSource::Unknown => KeyBindingMetaIndex(*self as u32),
}
}
pub fn from_meta(index: KeyBindingMetaIndex) -> Self {
Self::try_from_meta(index).unwrap()
}
pub fn try_from_meta(index: KeyBindingMetaIndex) -> Result<Self> {
Ok(match index {
match index {
Self::USER => KeybindSource::User,
Self::BASE => KeybindSource::Base,
Self::DEFAULT => KeybindSource::Default,
Self::VIM => KeybindSource::Vim,
_ => anyhow::bail!("Invalid keybind source {:?}", index),
})
_ => KeybindSource::Unknown,
}
}
}
@ -1014,7 +1014,7 @@ impl From<KeyBindingMetaIndex> for KeybindSource {
impl From<KeybindSource> for KeyBindingMetaIndex {
fn from(source: KeybindSource) -> Self {
return source.meta();
source.meta()
}
}