helix: Fix line selection after undoing delete - #55365
Conversation
|
|
||
| cx.set_state("oneˇ\ntwo\nthree", Mode::HelixNormal); | ||
| cx.simulate_keystrokes("d u x"); | ||
| cx.assert_state("«one\nˇ»two\nthree", Mode::HelixNormal); |
There was a problem hiding this comment.
Isn't the expected behaviour cx.assert_state("«oneˇ»\ntwo\nthree", Mode::HelixNormal); (selection and cursor on the same line)? I just checked in Helix. This assertion seems to match what I see in Zed (current main).
There was a problem hiding this comment.
Yes, the cursor is on a newline character but the visible selection is on a character before it. This is how it is right now (somewhat hacky implementation of a helix mode itself). I had some proposal how all of that could be refactored here, if you are interested -> #56768
This assertion seems to match what I see in Zed (current main).
In the current main branch you will end up selecting both one and two in this example:
oneˇ
two
three
I think it was this commit which is responsible for it -> 81da953
There was a problem hiding this comment.
To be more precise in our concrete example it would be this code -> https://github.com/zed-industries/zed/blob/main/crates/editor/src/element.rs#L152 but its all triggered because of this:
cursor_offset_on_selection: self.mode.is_visual() || self.mode.is_helix(),
There was a problem hiding this comment.
Indeed, I probably wasn't using the right sequence, I can see the difference with main now.
tomhoule
left a comment
There was a problem hiding this comment.
This is an improvement, and the implementation makes sense. Thanks for the contribution!
Closes zed-industries#55170 Fixes Helix mode undo selection history after `d` deletes the character under an empty cursor. Previously, `d` temporarily expanded the cursor to a one-character selection before deleting, and undo restored that temporary selection. When the deleted character was a newline, pressing `x` after undo selected additional line which was wrong. This preserves the original Helix selection as the undo-restored selection while keeping the existing delete behavior unchanged. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed Helix mode selecting one extra line after undoing a newline delete Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
Closes zed-industries#55170 Fixes Helix mode undo selection history after `d` deletes the character under an empty cursor. Previously, `d` temporarily expanded the cursor to a one-character selection before deleting, and undo restored that temporary selection. When the deleted character was a newline, pressing `x` after undo selected additional line which was wrong. This preserves the original Helix selection as the undo-restored selection while keeping the existing delete behavior unchanged. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed Helix mode selecting one extra line after undoing a newline delete Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
Closes zed-industries#55170 Fixes Helix mode undo selection history after `d` deletes the character under an empty cursor. Previously, `d` temporarily expanded the cursor to a one-character selection before deleting, and undo restored that temporary selection. When the deleted character was a newline, pressing `x` after undo selected additional line which was wrong. This preserves the original Helix selection as the undo-restored selection while keeping the existing delete behavior unchanged. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed Helix mode selecting one extra line after undoing a newline delete Co-authored-by: Tom Houlé <13155277+tomhoule@users.noreply.github.com>
Closes #55170
Fixes Helix mode undo selection history after
ddeletes the character under an empty cursor. Previously,dtemporarily expanded the cursor to a one-character selection before deleting, and undo restored that temporary selection. When the deleted character was a newline, pressingxafter undo selected additional line which was wrong.This preserves the original Helix selection as the undo-restored selection while keeping the existing delete behavior unchanged.
Self-Review Checklist:
Release Notes: