Cherry-picked keymap_ui: Don't panic on `KeybindSource::from_meta` (#34652) Closes #ISSUE Log error instead of panicking when `from_meta` is passed an invalid value Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
parent
ce0de10147
commit
3f32020785
2 changed files with 11 additions and 4 deletions
|
@ -992,13 +992,17 @@ impl KeybindSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_meta(index: KeyBindingMetaIndex) -> Self {
|
pub fn from_meta(index: KeyBindingMetaIndex) -> Self {
|
||||||
match index {
|
Self::try_from_meta(index).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_from_meta(index: KeyBindingMetaIndex) -> Result<Self> {
|
||||||
|
Ok(match index {
|
||||||
Self::USER => KeybindSource::User,
|
Self::USER => KeybindSource::User,
|
||||||
Self::BASE => KeybindSource::Base,
|
Self::BASE => KeybindSource::Base,
|
||||||
Self::DEFAULT => KeybindSource::Default,
|
Self::DEFAULT => KeybindSource::Default,
|
||||||
Self::VIM => KeybindSource::Vim,
|
Self::VIM => KeybindSource::Vim,
|
||||||
_ => unreachable!(),
|
_ => anyhow::bail!("Invalid keybind source {:?}", index),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,10 @@ impl KeymapEditor {
|
||||||
let mut string_match_candidates = Vec::new();
|
let mut string_match_candidates = Vec::new();
|
||||||
|
|
||||||
for key_binding in key_bindings {
|
for key_binding in key_bindings {
|
||||||
let source = key_binding.meta().map(settings::KeybindSource::from_meta);
|
let source = key_binding
|
||||||
|
.meta()
|
||||||
|
.map(settings::KeybindSource::try_from_meta)
|
||||||
|
.and_then(|source| source.log_err());
|
||||||
|
|
||||||
let keystroke_text = ui::text_for_keystrokes(key_binding.keystrokes(), cx);
|
let keystroke_text = ui::text_for_keystrokes(key_binding.keystrokes(), cx);
|
||||||
let ui_key_binding = Some(
|
let ui_key_binding = Some(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue