Skip to content

Commit b7d31fa

Browse files
authored
vim: Add helix mode toggle (#41454)
Just for parity with vim. Also prevents these toggles from having both enabled at the same time as that is a buggy state. Release Notes: - Added command to toggle helix mode
1 parent 1a223e2 commit b7d31fa

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

crates/vim/src/vim.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ actions!(
260260
[
261261
/// Toggles Vim mode on or off.
262262
ToggleVimMode,
263+
/// Toggles Helix mode on or off.
264+
ToggleHelixMode,
263265
]
264266
);
265267

@@ -274,9 +276,23 @@ pub fn init(cx: &mut App) {
274276
cx.observe_new(|workspace: &mut Workspace, _, _| {
275277
workspace.register_action(|workspace, _: &ToggleVimMode, _, cx| {
276278
let fs = workspace.app_state().fs.clone();
277-
let currently_enabled = Vim::enabled(cx);
279+
let currently_enabled = VimModeSetting::get_global(cx).0;
278280
update_settings_file(fs, cx, move |setting, _| {
279-
setting.vim_mode = Some(!currently_enabled)
281+
setting.vim_mode = Some(!currently_enabled);
282+
if let Some(helix_mode) = &mut setting.helix_mode {
283+
*helix_mode = false;
284+
}
285+
})
286+
});
287+
288+
workspace.register_action(|workspace, _: &ToggleHelixMode, _, cx| {
289+
let fs = workspace.app_state().fs.clone();
290+
let currently_enabled = HelixModeSetting::get_global(cx).0;
291+
update_settings_file(fs, cx, move |setting, _| {
292+
setting.helix_mode = Some(!currently_enabled);
293+
if let Some(vim_mode) = &mut setting.vim_mode {
294+
*vim_mode = false;
295+
}
280296
})
281297
});
282298

crates/zed/src/zed/quick_action_bar.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ui::{
2222
ButtonStyle, ContextMenu, ContextMenuEntry, DocumentationEdge, DocumentationSide, IconButton,
2323
IconName, IconSize, PopoverMenu, PopoverMenuHandle, Tooltip, prelude::*,
2424
};
25-
use vim_mode_setting::VimModeSetting;
25+
use vim_mode_setting::{HelixModeSetting, VimModeSetting};
2626
use workspace::item::ItemBufferKind;
2727
use workspace::{
2828
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, item::ItemHandle,
@@ -307,6 +307,7 @@ impl Render for QuickActionBar {
307307
let editor = editor.downgrade();
308308
let editor_settings_dropdown = {
309309
let vim_mode_enabled = VimModeSetting::get_global(cx).0;
310+
let helix_mode_enabled = HelixModeSetting::get_global(cx).0;
310311

311312
PopoverMenu::new("editor-settings")
312313
.trigger_with_tooltip(
@@ -583,10 +584,25 @@ impl Render for QuickActionBar {
583584
move |window, cx| {
584585
let new_value = !vim_mode_enabled;
585586
VimModeSetting::override_global(VimModeSetting(new_value), cx);
587+
HelixModeSetting::override_global(HelixModeSetting(false), cx);
586588
window.refresh();
587589
}
588590
},
589591
);
592+
menu = menu.toggleable_entry(
593+
"Helix Mode",
594+
helix_mode_enabled,
595+
IconPosition::Start,
596+
None,
597+
{
598+
move |window, cx| {
599+
let new_value = !helix_mode_enabled;
600+
HelixModeSetting::override_global(HelixModeSetting(new_value), cx);
601+
VimModeSetting::override_global(VimModeSetting(false), cx);
602+
window.refresh();
603+
}
604+
}
605+
);
590606

591607
menu
592608
}

0 commit comments

Comments
 (0)