From 2fae4c7c724c1ee81b5fc7444ed79b4eade36504 Mon Sep 17 00:00:00 2001
From: Jonathan Hart <43473765+Quplet@users.noreply.github.com>
Date: Tue, 9 Sep 2025 15:18:22 -0400
Subject: [PATCH] vim: Make indenting selected lines with `>` and `<` in Helix
mode no longer deselect them (#37665)
Improves Helix compatibility by making the Indent keybinds `<` and `>`
no longer deselect lines if they're selected.
Post Indent action current Zed release:
(Cursor is on the beginning of the first line)
Post Indent action in Helix:
Post Indent action in this PR:
Release Notes:
- Fixed selected lines indented with `<` and `>` deselecting in Helix
mode
---
crates/vim/src/indent.rs | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/crates/vim/src/indent.rs b/crates/vim/src/indent.rs
index 7ef204de0f626f03f11054351ff9e711fc7b9c91..927edf4d9aa01502fd2112c1cb5b3fb5af12145f 100644
--- a/crates/vim/src/indent.rs
+++ b/crates/vim/src/indent.rs
@@ -5,6 +5,8 @@ use editor::{Bias, Editor, display_map::ToDisplayPoint};
use gpui::actions;
use gpui::{Context, Window};
use language::SelectionGoal;
+use settings::Settings;
+use vim_mode_setting::HelixModeSetting;
#[derive(PartialEq, Eq)]
pub(crate) enum IndentDirection {
@@ -37,7 +39,9 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context) {
for _ in 0..count {
editor.indent(&Default::default(), window, cx);
}
- vim.restore_selection_cursors(editor, window, cx, original_positions);
+ if !HelixModeSetting::get_global(cx).0 {
+ vim.restore_selection_cursors(editor, window, cx, original_positions);
+ }
});
});
if vim.mode.is_visual() {
@@ -56,7 +60,9 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context) {
for _ in 0..count {
editor.outdent(&Default::default(), window, cx);
}
- vim.restore_selection_cursors(editor, window, cx, original_positions);
+ if !HelixModeSetting::get_global(cx).0 {
+ vim.restore_selection_cursors(editor, window, cx, original_positions);
+ }
});
});
if vim.mode.is_visual() {
@@ -183,6 +189,20 @@ mod test {
.assert_eq("« hello\n ˇ» world\n");
}
+ #[gpui::test]
+ async fn test_indent_hx(cx: &mut gpui::TestAppContext) {
+ let mut cx = VimTestContext::new(cx, true).await;
+ cx.enable_helix();
+
+ cx.set_state("«Hello\nWorldˇ»\n", Mode::HelixNormal);
+
+ cx.simulate_keystrokes(">");
+ cx.assert_state(" «Hello\n Worldˇ»\n", Mode::HelixNormal);
+
+ cx.simulate_keystrokes("<");
+ cx.assert_state("«Hello\nWorldˇ»\n", Mode::HelixNormal);
+ }
+
#[gpui::test]
async fn test_autoindent_op(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;