vim: Fix escape key switching back to default mode instead of normal mode (#31843)

Closes #31728

This PR introduced new setting `"helix_mode"`. Enabling which will
enable the `vim_mode` along with `helix` behavior.

This solves issue where `vim`'s `default_mode` was being used to switch
between mode instead of opening in `default_mode`.

When `helix_mode` is enabled switcing to `Normal mode` will now switch
to `HelixNormal`


Release Notes:

- Fixed - escape key not switching to normal mode when default_mode is
insert
- Added - `helix_mode` setting to enable/disable helix key bindings

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Sanjeev Shrestha 2025-06-19 03:11:12 +05:45 committed by GitHub
parent d2ca68bd5d
commit ab189b898d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 72 additions and 14 deletions

View file

@ -44,6 +44,7 @@ use std::{mem, ops::Range, sync::Arc};
use surrounds::SurroundsType;
use theme::ThemeSettings;
use ui::{IntoElement, SharedString, px};
use vim_mode_setting::HelixModeSetting;
use vim_mode_setting::VimModeSetting;
use workspace::{self, Pane, Workspace};
@ -359,8 +360,13 @@ impl Vim {
pub fn new(window: &mut Window, cx: &mut Context<Editor>) -> Entity<Self> {
let editor = cx.entity().clone();
let mut initial_mode = VimSettings::get_global(cx).default_mode;
if initial_mode == Mode::Normal && HelixModeSetting::get_global(cx).0 {
initial_mode = Mode::HelixNormal;
}
cx.new(|cx| Vim {
mode: VimSettings::get_global(cx).default_mode,
mode: initial_mode,
last_mode: Mode::Normal,
temp_mode: false,
exit_temporary_mode: false,
@ -445,7 +451,11 @@ impl Vim {
vim.update(cx, |_, cx| {
Vim::action(editor, cx, |vim, _: &SwitchToNormalMode, window, cx| {
vim.switch_mode(vim.default_mode(cx), false, window, cx)
if HelixModeSetting::get_global(cx).0 {
vim.switch_mode(Mode::HelixNormal, false, window, cx)
} else {
vim.switch_mode(Mode::Normal, false, window, cx)
}
});
Vim::action(editor, cx, |vim, _: &SwitchToInsertMode, window, cx| {
@ -748,10 +758,6 @@ impl Vim {
cx.on_release(|_, _| drop(subscription)).detach();
}
pub fn default_mode(&self, cx: &App) -> Mode {
VimSettings::get_global(cx).default_mode
}
pub fn editor(&self) -> Option<Entity<Editor>> {
self.editor.upgrade()
}
@ -766,7 +772,7 @@ impl Vim {
}
pub fn enabled(cx: &mut App) -> bool {
VimModeSetting::get_global(cx).0
VimModeSetting::get_global(cx).0 || HelixModeSetting::get_global(cx).0
}
/// Called whenever an keystroke is typed so vim can observe all actions