Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/codemirror-vim-core/test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion packages/codemirror-vim-core/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down