vim: Fix incorrect bracket matching for symmetric quotes in cs operator#52321
Merged
ConradIrwin merged 3 commits intozed-industries:mainfrom Apr 17, 2026
Merged
vim: Fix incorrect bracket matching for symmetric quotes in cs operator#52321ConradIrwin merged 3 commits intozed-industries:mainfrom
cs operator#52321ConradIrwin merged 3 commits intozed-industries:mainfrom
Conversation
Member
|
Thanks for fixing this! |
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.
Context
Closes #46698
This PR fixes a bug where the
cs(change surrounds) operator fails on symmetric delimiters like quotes.In a sequence like
c s ' ", Zed previously performed two independent searches. For a line likeI'm 'goˇod', the first step (cs') correctly moves the cursor to the second quote:I'm ˇ'good'. However, when the replacement character"is pressed,change_surroundswould perform another scan from the new cursor position. Because quotes are symmetric, this second search would incorrectly match'm 'as the target pair, leading to a broken result likeI"m "good'.I've refactored the workflow to ensure the search happens only once.
prepare_and_move_to_valid_bracket_pairnow computes and stores theAnchorpositions of the detected pair directly into the operator state.change_surroundsthen simply reuses these anchors instead of re-executing the search. This ensures correctness for quotes while remaining consistent with Vim/Neovim cursor behavior. While this slightly increases coupling between these two functions, it is an intentional trade-off since they exclusively serve thecsoperation.How to Review
The main changes are in
crates/vim/src/surrounds.rs. I renamedcheck_and_move_to_valid_bracket_pairtoprepare_and_move_to_valid_bracket_pairand updated it to return the detected bracket anchors. Inchange_surrounds, I removed the redundant search logic and updated it to perform the replacement using the provided anchors. You can also see the updatedOperator::ChangeSurroundsenum variant incrates/vim/src/state.rswhich now carries the anchor data.Self-Review Checklist
Release Notes:
csVim operator incorrectly identified symmetric quotes in certain contexts.