1//! Contains the [`VimModeSetting`] and [`HelixModeSetting`] used to enable/disable Vim and Helix modes.
2//!
3//! This is in its own crate as we want other crates to be able to enable or
4//! disable Vim/Helix modes without having to depend on the `vim` crate in its
5//! entirety.
6
7use anyhow::Result;
8use gpui::App;
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11use settings::{Settings, SettingsSources};
12
13/// Initializes the `vim_mode_setting` crate.
14pub fn init(cx: &mut App) {
15 EditorModeSetting::register(cx);
16}
17
18/// Whether or not to enable Vim mode.
19///
20/// Default: `EditMode::Default`
21pub struct EditorModeSetting(pub EditorMode);
22
23#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
24pub enum EditorMode {
25 Vim,
26 Helix,
27 #[default]
28 Default,
29}
30
31impl Settings for EditorModeSetting {
32 const KEY: Option<&'static str> = Some("editor_mode");
33
34 type FileContent = Option<EditorMode>;
35
36 fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
37 Ok(Self(
38 sources
39 .user
40 .or(sources.server)
41 .copied()
42 .flatten()
43 .unwrap_or(sources.default.ok_or_else(Self::missing_default)?),
44 ))
45 }
46
47 fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
48 // TODO: could possibly check if any of the `vim.<foo>` keys are set?
49 }
50}