Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

keymap_ui: Don't panic on `KeybindSource::from_meta` (#34652)

Ben Kunkle4314b3528898
diff --git a/crates/settings/src/keymap_file.rs b/crates/settings/src/keymap_file.rs
index e6a32f731b1..3a01d889c47 100644
--- a/crates/settings/src/keymap_file.rs
+++ b/crates/settings/src/keymap_file.rs
@@ -992,13 +992,17 @@ impl KeybindSource {
}
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::BASE => KeybindSource::Base,
Self::DEFAULT => KeybindSource::Default,
Self::VIM => KeybindSource::Vim,
- _ => unreachable!(),
- }
+ _ => anyhow::bail!("Invalid keybind source {:?}", index),
+ })
}
}
diff --git a/crates/settings_ui/src/keybindings.rs b/crates/settings_ui/src/keybindings.rs
index 2e00426c1bf..29927c41967 100644
--- a/crates/settings_ui/src/keybindings.rs
+++ b/crates/settings_ui/src/keybindings.rs
@@ -567,7 +567,10 @@ impl KeymapEditor {
let mut string_match_candidates = Vec::new();
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 ui_key_binding = Some(