# vim: Fix Helix cursor position when deleting to end of line \(\#59987\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/27a9e2057b71ef84a1dbe06fc51ac04c62f420d4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 27a9e2057b71ef84a1dbe06fc51ac04c62f420d4

Requested commit: 27a9e2057b71ef84a1dbe06fc51ac04c62f420d4

Commit: 27a9e2057b71ef84a1dbe06fc51ac04c62f420d4

Tree: 94175badcf0ad7dfa61680487712db3b2c475ac2

Author: Ibrahim Khan

Committer: GitHub

## Message

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

## Why / What

Fixes #58702.

In Helix mode the block cursor is a one-character selection that can
rest on the
trailing newline at the end of a line. When you select to the end of a
line
(excluding the newline) and press `d`, Helix leaves the cursor on the
newline.
Zed instead clamped the cursor onto the character immediately to the
left of the
deleted selection.

The shared `visual_delete` always re-clipped the post-deletion cursor at
line
ends (`set_clip_at_line_ends(true)`), which is correct for Vim normal
mode but
contradicts Helix mode, where `Vim::clip_at_line_ends()` is `false`.
This also
made Helix inconsistent with itself: deleting a whole line left the
cursor on the
newline, but deleting to the end of a non-empty line clamped it onto the
previous
character. The fix honors the active mode's clip policy, so Helix keeps
the
cursor on the newline.

## Testing

- Added `test_delete_to_end_of_line_keeps_cursor_on_newline` reproducing
#58702.
- Corrected `test_helix_select_end_of_line`; its mid-line assertion had
captured
the pre-fix (clamped) cursor position. Its whole-line assertion already
expected the cursor on the newline, so the test is now internally
consistent.
- `cargo test -p vim`: 540 passed, 0 failed.
- Vim visual-mode delete is unchanged (`is_helix()` is false for Vim
modes).

Release Notes:

- Fixed Helix mode placing the cursor on the wrong character after
deleting a selection that ends at the end of a line.

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
```

## Parents

- [e1ec575d3f78968c8cbc4168cdda40cac5e2aa8c](https://git.cafe/gitcafe/zed/commit/e1ec575d3f78968c8cbc4168cdda40cac5e2aa8c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/27a9e2057b71ef84a1dbe06fc51ac04c62f420d4?format=markdown)
