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'); 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);