Fix da}/da) text objects picking the wrong block when the cursor is before a block - #278
Open
DeepanshuPal wants to merge 2 commits into
Open
DeepanshuPal wants to merge 2 commits into
DeepanshuPal wants to merge 2 commits into
Conversation
When no enclosing pair is found, the fallback searched ahead for the typed bracket. For a closing bracket that found the first closed block in the document instead of the first one opened ahead of the cursor. Search for the opening bracket instead, matching what {, ( and [ already did.
Fixes replit#264
Co-Authored-By: Claude <noreply@anthropic.com>
Regression tests: closing-bracket text objects pick the first block opened ahead of the cursor, matching da{.
Co-Authored-By: Claude <noreply@anthropic.com>
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio. |
This branch has not been deployed
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.
Why
Fixes #264. With the cursor before any block,
da}deleted the first closed block in the document (the innerwhilebody in the issue's example) instead of the first block opened ahead of the cursor.da{already picked the right one, and so does real Vim (checked against vim 8.2:da}andda{both delete the outer block).What changed
In the text-object code in
packages/codemirror-vim-core/vim.js, when no enclosing pair is found it searches ahead for a bracket and selects around it. It searched for the typed character, so a typed}found the first closing}, which belongs to an inner block. It now searches for the opening bracket when a closing one was typed (),},],>), the same thing the opening forms already did. Three lines, no change when the cursor is inside a block.Test plan
Added three tests in
packages/codemirror-vim-core/test/vim_test.js(da{,da}andda)with the cursor before a block). Before the fix theda}andda)tests fail; after it:Manual: doc
f(a) {/while (x) {/y;/}/z;/}with the cursor at the start, pressda}. Before: only the innerwhileblock is removed. After: the whole outer block is removed, as in Vim.AI assistance disclosure: this change was written with an AI coding assistant (Claude), noted in the commit trailers.