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 gpui::App;
8use settings::{Settings, SettingsContent};
9
10/// Initializes the `vim_mode_setting` crate.
11pub fn init(cx: &mut App) {
12 VimModeSetting::register(cx);
13 HelixModeSetting::register(cx);
14}
15
16pub struct VimModeSetting(pub bool);
17
18impl Settings for VimModeSetting {
19 fn from_defaults(content: &SettingsContent, _cx: &mut App) -> Self {
20 Self(content.vim_mode.unwrap())
21 }
22
23 fn refine(&mut self, content: &SettingsContent, _cx: &mut App) {
24 if let Some(vim_mode) = content.vim_mode {
25 self.0 = vim_mode;
26 }
27 }
28
29 fn import_from_vscode(_vscode: &settings::VsCodeSettings, _content: &mut SettingsContent) {
30 // TODO: could possibly check if any of the `vim.<foo>` keys are set?
31 }
32}
33
34pub struct HelixModeSetting(pub bool);
35
36impl Settings for HelixModeSetting {
37 fn from_defaults(content: &SettingsContent, _cx: &mut App) -> Self {
38 Self(content.helix_mode.unwrap())
39 }
40
41 fn refine(&mut self, content: &SettingsContent, _cx: &mut App) {
42 if let Some(helix_mode) = content.helix_mode {
43 self.0 = helix_mode;
44 }
45 }
46
47 fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut SettingsContent) {}
48}