Add "workspace: Toggle Vim Mode"

Co-Authored-By: Marshall <elliott.codes@gmail.com>
This commit is contained in:
Conrad Irwin 2023-10-20 11:41:13 -06:00
parent 199740902a
commit c7991ef04c

View file

@ -25,7 +25,7 @@ pub use mode_indicator::ModeIndicator;
use motion::Motion; use motion::Motion;
use normal::normal_replace; use normal::normal_replace;
use serde::Deserialize; use serde::Deserialize;
use settings::{Setting, SettingsStore}; use settings::{update_settings_file, Setting, SettingsStore};
use state::{EditorState, Mode, Operator, RecordedSelection, WorkspaceState}; use state::{EditorState, Mode, Operator, RecordedSelection, WorkspaceState};
use std::{ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
use visual::{visual_block_motion, visual_replace}; use visual::{visual_block_motion, visual_replace};
@ -48,6 +48,7 @@ actions!(
vim, vim,
[Tab, Enter, Object, InnerObject, FindForward, FindBackward] [Tab, Enter, Object, InnerObject, FindForward, FindBackward]
); );
actions!(workspace, [ToggleVimMode]);
impl_actions!(vim, [Number, SwitchMode, PushOperator]); impl_actions!(vim, [Number, SwitchMode, PushOperator]);
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -88,6 +89,14 @@ pub fn init(cx: &mut AppContext) {
Vim::active_editor_input_ignored("\n".into(), cx) Vim::active_editor_input_ignored("\n".into(), cx)
}); });
cx.add_action(|workspace: &mut Workspace, _: &ToggleVimMode, cx| {
let fs = workspace.app_state().fs.clone();
let currently_enabled = settings::get::<VimModeSetting>(cx).0;
update_settings_file::<VimModeSetting>(fs, cx, move |setting| {
*setting = Some(!currently_enabled)
})
});
// Any time settings change, update vim mode to match. The Vim struct // Any time settings change, update vim mode to match. The Vim struct
// will be initialized as disabled by default, so we filter its commands // will be initialized as disabled by default, so we filter its commands
// out when starting up. // out when starting up.