From aaf7e45a212684bbf88ab2b285c84d534464ef22 Mon Sep 17 00:00:00 2001 From: Deepanshu Pal <40927968+DeepanshuPal@users.noreply.github.com> Date: Sun, 4 Oct 2026 02:25:53 +0530 Subject: [PATCH 1/2] Fix da}/da) text objects picking the wrong block before a block 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 #264 Co-Authored-By: Claude --- packages/codemirror-vim-core/vim.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/codemirror-vim-core/vim.js b/packages/codemirror-vim-core/vim.js index 3cafa6b..533c7c5 100644 --- a/packages/codemirror-vim-core/vim.js +++ b/packages/codemirror-vim-core/vim.js @@ -2614,7 +2614,9 @@ export function initVim(CM) { move = true; tmp = selectCompanionObject(cm, head, character, inclusive); if (!tmp) { - var sc = cm.getSearchCursor(new RegExp("\\" + character, "g"), head) + // Look ahead for the opening bracket, whichever form was typed. + var openChar = ')}]>'.indexOf(character) >= 0 ? mirroredPairs[character] : character; + var sc = cm.getSearchCursor(new RegExp("\\" + openChar, "g"), head) if (sc.find()) { // @ts-ignore tmp = selectCompanionObject(cm, sc.from(), character, inclusive); From 7c4c3895eee7d0ece7035143db761ad61ba233fd Mon Sep 17 00:00:00 2001 From: Deepanshu Pal <40927968+DeepanshuPal@users.noreply.github.com> Date: Sun, 4 Oct 2026 02:26:32 +0530 Subject: [PATCH 2/2] Test da}/da) before a block (#264) Regression tests: closing-bracket text objects pick the first block opened ahead of the cursor, matching da{. Co-Authored-By: Claude --- packages/codemirror-vim-core/test/vim_test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/codemirror-vim-core/test/vim_test.js b/packages/codemirror-vim-core/test/vim_test.js index 789fc06..10c71a7 100644 --- a/packages/codemirror-vim-core/test/vim_test.js +++ b/packages/codemirror-vim-core/test/vim_test.js @@ -1623,6 +1623,14 @@ testEdit('da{_middle_spc', 'a{\n\tbar\n}b', /r/, 'da{', 'ab'); testEdit('da}_middle_spc', 'a{\n\tbar\n}b', /r/, 'da}', 'ab'); testEdit('daB_middle_spc', 'a{\n\tbar\n}b', /r/, 'daB', 'ab'); +// Cursor before any block: the closing-bracket forms must behave like the +// opening-bracket forms and pick the first block opened ahead of the cursor, +// not the first closing bracket in the document (replit/codemirror-vim#264). +var outsideBlockDoc = 'f(a) {\n while (x) {\n y;\n }\n z;\n}'; +testEdit('da{_before_block_selects_first_opened_block', outsideBlockDoc, /f/, 'da{', 'f(a) '); +testEdit('da}_before_block_selects_first_opened_block', outsideBlockDoc, /f/, 'da}', 'f(a) '); +testEdit('da)_before_block_selects_first_opened_pair', 'x f(a(b)) y', /x/, 'da)', 'x f y'); + // open and close on diff lines, open indented less than close testEdit('di{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di{', 'a{}b'); testEdit('di}_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di}', 'a{}b');