restructure base keymap

This commit is contained in:
Ben Kunkle
2025-09-01 17:19:29 -05:00
parent c33afaad6e
commit 1e1939832e
3 changed files with 20 additions and 9 deletions

View File

@@ -187,7 +187,7 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
);
update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting, _| {
*setting = Some(base_keymap)
setting.base_keymap = Some(base_keymap)
});
}

View File

@@ -325,7 +325,7 @@ fn render_base_keymap_section(tab_index: &mut isize, cx: &mut App) -> impl IntoE
let fs = <dyn Fs>::global(cx);
update_settings_file::<BaseKeymap>(fs, cx, move |setting, _| {
*setting = Some(keymap_base);
setting.base_keymap = Some(keymap_base);
});
}
}

View File

@@ -100,25 +100,36 @@ impl BaseKeymap {
}
}
impl Settings for BaseKeymap {
const KEY: Option<&'static str> = Some("base_keymap");
#[derive(
Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default, SettingsUi,
)]
// extracted so that it can be an option, and still work with derive(SettingsUi)
pub struct BaseKeymapSetting {
pub base_keymap: Option<BaseKeymap>,
}
type FileContent = Option<Self>;
impl Settings for BaseKeymap {
const KEY: Option<&'static str> = None;
type FileContent = BaseKeymapSetting;
fn load(
sources: SettingsSources<Self::FileContent>,
_: &mut gpui::App,
) -> anyhow::Result<Self> {
if let Some(Some(user_value)) = sources.user.copied() {
if let Some(Some(user_value)) = sources.user.map(|setting| setting.base_keymap) {
return Ok(user_value);
}
if let Some(Some(server_value)) = sources.server.copied() {
if let Some(Some(server_value)) = sources.server.map(|setting| setting.base_keymap) {
return Ok(server_value);
}
sources.default.ok_or_else(Self::missing_default)
sources
.default
.base_keymap
.ok_or_else(Self::missing_default)
}
fn import_from_vscode(_vscode: &VsCodeSettings, current: &mut Self::FileContent) {
*current = Some(BaseKeymap::VSCode);
current.base_keymap = Some(BaseKeymap::VSCode);
}
}