vim: Apply linked edits for delete/change/substitute#48458
Merged
dinocosta merged 8 commits intozed-industries:mainfrom Feb 19, 2026
Merged
vim: Apply linked edits for delete/change/substitute#48458dinocosta merged 8 commits intozed-industries:mainfrom
dinocosta merged 8 commits intozed-industries:mainfrom
Conversation
Fixes zed-industries#35941. Tests: cargo test -p vim test_vim_linked_edits_
Contributor
* Remove `Editor.insert_with_autoindent_mode` seeing as it was mostly a wrapper around the replace selections method * Rename `Editor.replace_selections_with_text` to simply `Editor.replace_selections` * Update callers
Replace 4 duplicated inline linked edit build and apply blocks across `handle_input`, `replace_selections`, `do_completion`, and `backspace` with a shared `LinkedEdits` struct in the `linked_editing_ranges` module. - Introduce `LinkedEdits` with `push`(), `apply`(), and `apply_with_left_expansion()` - Store anchor ranges and defer point resolution to apply time - Deduplicate backspace's empty-range expansion logic via `apply_inner` - Fix `do_completion` allocating a new String per range instead of sharing Arc<str> - Remove redundant buffer_id check in backspace (already handled by linked_editing_ranges_for) - Add unit tests for typing, backspace, and selection replacement with linked edits
Member
|
@ixacik I've pushed some smaller commits, mainly extracting the linked edits logic into a different module and struct and will merge this after the new stable release is published, as I want to let this one sit in Nightly for a bit to double-check these changes don't break any tests or functionality ✌️ |
Introduce `Editor::linked_edits_for_selections` as a public helper that collects linked edits for the current selections into a `LinkedEdits` value. This decouples linked edit collection from the primary edit strategy, allowing callers to choose between `replace_selections`, which repositions cursors, and `editor.edit()`, which does not. Use this helper in `replace_selections` to simplify its linked edit logic, and in vim's substitute command to preserve its original lightweight `editor.edit()` semantics, fixing failing tests which brokwn when substitute was changed to use `delete_selections_with_linked_edits`.
Member
|
@ixacik Sorry, I ended up taking longer to fix this than I originally expected... 😔 Locally all the tests are passing so CI/CD should soon be fixed, will either merge later today or tomorrow, seeing as we're doing a new release today and I want this to sit in Nightly for a while, sorry! |
* Update the `editor::Editor.delete` method in order to also leverage the new `LinkedEdits` implementation, so linked edits are correctly applied on delete and not only on backspace. * Update the `editor::Editor.backspace` method to leverage the `editor::Editor.linked_edits_for_selections` method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #35941
Summary:
x,c iw,s, visualc, and visuals.Demo:
https://github.com/user-attachments/assets/1ed7278a-4a75-46bc-bd77-80a794b9712e
Release Notes: