Skip to content

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
replit:masterfrom
DeepanshuPal:fix/closing-bracket-textobject-264
Open

DeepanshuPal wants to merge 2 commits into
replit:masterfrom
DeepanshuPal:fix/closing-bracket-textobject-264

Conversation

@DeepanshuPal

Copy link
Copy Markdown

Why

Fixes #264. With the cursor before any block, da} deleted the first closed block in the document (the inner while body 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} and da{ 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} and da) with the cursor before a block). Before the fix the da} and da) tests fail; after it:

pnpm test            # 714 passing (711 before + 3 new), 0 failing
pnpm --filter codemirror-vim-core run typecheck   # clean

Manual: doc f(a) { / while (x) { / y; / } / z; / } with the cursor at the start, press da}. Before: only the inner while block 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.

DeepanshuPal and others added 2 commits October 4, 2026 02:25
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-a44d115bc1

wiz-a44d115bc1 Bot commented Oct 3, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 2 Medium
Software Management Finding Software Management Findings -
Total 2 Medium

View scan details in Wiz

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Curly Brace deletion behaving unexpectedly

1 participant