Skip to content

vim: Apply linked edits for delete/change/substitute#48458

Merged
dinocosta merged 8 commits intozed-industries:mainfrom
ixacik:fix/vim-linked-edits
Feb 19, 2026
Merged

vim: Apply linked edits for delete/change/substitute#48458
dinocosta merged 8 commits intozed-industries:mainfrom
ixacik:fix/vim-linked-edits

Conversation

@ixacik
Copy link
Contributor

@ixacik ixacik commented Feb 5, 2026

Closes #35941

Summary:

  • Ensure Vim delete/change/substitute and visual delete apply linked edits.
  • Add editor helper to apply linked edits when deleting selections.
  • Add linked‑edit tests for x, c iw, s, visual c, and visual s.

Demo:
https://github.com/user-attachments/assets/1ed7278a-4a75-46bc-bd77-80a794b9712e

Release Notes:

  • Fixed linked edits for delete/change/substitute commands so tag pairs stay in sync.

Fixes zed-industries#35941.

Tests: cargo test -p vim test_vim_linked_edits_
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 5, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Feb 5, 2026
@maxdeviant maxdeviant changed the title vim: apply linked edits for delete/change/substitute vim: Apply linked edits for delete/change/substitute Feb 5, 2026
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Feb 5, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against b3fdea4

Copy link
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for picking this one up and including some tests @ixacik ! 🙌

* 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
@dinocosta
Copy link
Member

dinocosta commented Feb 9, 2026

@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`.
@dinocosta dinocosta requested a review from a team as a code owner February 18, 2026 12:46
@dinocosta
Copy link
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.
@dinocosta dinocosta enabled auto-merge (squash) February 19, 2026 12:48
@dinocosta dinocosta merged commit bad3df6 into zed-industries:main Feb 19, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linked edits dont account for vim specific edits

3 participants