Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

vim: Fix Helix cursor position when deleting to end of line (#59987)

Ibrahim Khan27a9e2057b71
diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs
index 2642221b31c..79c65b227bb 100644
--- a/crates/vim/src/helix.rs
+++ b/crates/vim/src/helix.rs
@@ -2341,6 +2341,31 @@ mod test {
);
}
+ // Deleting a selection that ends at the last non-newline character should
+ // leave the cursor on the newline (matching Helix), not clamp it onto the
+ // character to the left of the selection.
+ #[gpui::test]
+ async fn test_delete_to_end_of_line_keeps_cursor_on_newline(cx: &mut gpui::TestAppContext) {
+ let mut cx = VimTestContext::new(cx, true).await;
+ cx.enable_helix();
+
+ cx.set_state(
+ indoc! {"
+ ab«cdefgˇ»
+ hij"},
+ Mode::HelixNormal,
+ );
+
+ cx.simulate_keystrokes("d");
+
+ cx.assert_state(
+ indoc! {"
+ abˇ
+ hij"},
+ Mode::HelixNormal,
+ );
+ }
+
// #[gpui::test]
// async fn test_delete_character_end_of_buffer(cx: &mut gpui::TestAppContext) {
// let mut cx = VimTestContext::new(cx, true).await;
@@ -2985,11 +3010,11 @@ mod test {
cx.simulate_keystrokes("v g l d");
cx.assert_state("ˇ\nfox jumps over", Mode::HelixNormal);
- // same from the middle of a line — cursor lands on the last
- // remaining character (the space) after delete
+ // same from the middle of a line — the cursor rests on the trailing
+ // newline, matching Helix and the whole-line case above.
cx.set_state("The ˇquick brown\nfox jumps over", Mode::HelixNormal);
cx.simulate_keystrokes("v g l d");
- cx.assert_state("Theˇ \nfox jumps over", Mode::HelixNormal);
+ cx.assert_state("The ˇ\nfox jumps over", Mode::HelixNormal);
}
#[gpui::test]
diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs
index e715e98a655..e9c3f22c23c 100644
--- a/crates/vim/src/visual.rs
+++ b/crates/vim/src/visual.rs
@@ -695,8 +695,9 @@ impl Vim {
}
editor.delete_selections_with_linked_edits(window, cx);
- // Fixup cursor position after the deletion
- editor.set_clip_at_line_ends(true, cx);
+ // Fixup cursor position after the deletion. Helix keeps the
+ // cursor on the trailing newline, so only clip in Vim modes.
+ editor.set_clip_at_line_ends(!vim.mode.is_helix(), cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(&mut |map, selection| {
let mut cursor = selection.head().to_point(map);