1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use settings::Setting;
4
5#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
6pub enum BaseKeymap {
7 #[default]
8 VSCode,
9 JetBrains,
10 SublimeText,
11 Atom,
12 TextMate,
13}
14
15impl BaseKeymap {
16 pub const OPTIONS: [(&'static str, Self); 5] = [
17 ("VSCode (Default)", Self::VSCode),
18 ("Atom", Self::Atom),
19 ("JetBrains", Self::JetBrains),
20 ("Sublime Text", Self::SublimeText),
21 ("TextMate", Self::TextMate),
22 ];
23
24 pub fn asset_path(&self) -> Option<&'static str> {
25 match self {
26 BaseKeymap::JetBrains => Some("keymaps/jetbrains.json"),
27 BaseKeymap::SublimeText => Some("keymaps/sublime_text.json"),
28 BaseKeymap::Atom => Some("keymaps/atom.json"),
29 BaseKeymap::TextMate => Some("keymaps/textmate.json"),
30 BaseKeymap::VSCode => None,
31 }
32 }
33
34 pub fn names() -> impl Iterator<Item = &'static str> {
35 Self::OPTIONS.iter().map(|(name, _)| *name)
36 }
37
38 pub fn from_names(option: &str) -> BaseKeymap {
39 Self::OPTIONS
40 .iter()
41 .copied()
42 .find_map(|(name, value)| (name == option).then(|| value))
43 .unwrap_or_default()
44 }
45}
46
47impl Setting for BaseKeymap {
48 const KEY: Option<&'static str> = Some("base_keymap");
49
50 type FileContent = Option<Self>;
51
52 fn load(
53 default_value: &Self::FileContent,
54 user_values: &[&Self::FileContent],
55 _: &gpui::AppContext,
56 ) -> anyhow::Result<Self>
57 where
58 Self: Sized,
59 {
60 Ok(user_values
61 .first()
62 .and_then(|v| **v)
63 .unwrap_or(default_value.unwrap()))
64 }
65}