va( searches forward (#8045)

Fixes #8024
This commit is contained in:
smallkirby 2022-12-28 14:40:49 +09:00 committed by GitHub
parent 8fd5c45557
commit 2508ed8f11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 1 deletions

View File

@ -1841,7 +1841,21 @@ export abstract class MoveInsideCharacter extends ExpandingSelection {
// First, search backwards for the opening character of the sequence
let openPos = PairMatcher.nextPairedChar(selStart, closingChar, vimState, true);
if (openPos === undefined) {
return failedMovement(vimState);
// If opening character not found, search forwards
let lineNum = selStart.line;
while (true) {
if (lineNum >= vimState.document.lineCount) {
break;
}
const lineText = vimState.document.lineAt(lineNum).text;
const matchIndex = lineText.indexOf(this.charToMatch);
if (matchIndex !== -1) {
openPos = new Position(lineNum, matchIndex);
break;
}
++lineNum;
}
if (openPos === undefined) return failedMovement(vimState);
}
// Next, search forwards for the closing character which matches

View File

@ -594,6 +594,14 @@ suite('Mode Visual', () => {
endMode: Mode.Normal,
});
newTest({
title: `Can do di${buttonToPress} on a matching bracket from outside bracket`,
start: [`| ${start} one ${start} two ${start} three ${end} four ${end} five ${end}`],
keysPressed: `di${buttonToPress}`,
end: [` ${start}|${end}`],
endMode: Mode.Normal,
});
newTest({
title: `Can do i${buttonToPress} on multiple matching brackets`,
start: [`${start} one ${start} two ${start} th|ree ${end} four ${end} five ${end}`],
@ -629,6 +637,14 @@ suite('Mode Visual', () => {
endMode: Mode.Normal,
});
newTest({
title: 'Cannot do vit on a matching tag from outside tag',
start: ['|one <blink>hello</blink> two'],
keysPressed: 'vitd',
end: ['|ne <blink>hello</blink> two'],
endMode: Mode.Normal,
});
newTest({
title:
'Count-prefixed vit alternates expanding selection between inner and outer tag brackets',
@ -645,6 +661,14 @@ suite('Mode Visual', () => {
end: ['one | two'],
endMode: Mode.Normal,
});
newTest({
title: 'Cannot do vat on a matching tag from from outside tag',
start: ['|one <blink>hello</blink> two'],
keysPressed: 'vatd',
end: ['|ne <blink>hello</blink> two'],
endMode: Mode.Normal,
});
});
newTest({
@ -695,6 +719,22 @@ suite('Mode Visual', () => {
endMode: Mode.Normal,
});
newTest({
title: 'Can do vi) on a matching parenthesis from outside parathesis',
start: ['|test(test)'],
keysPressed: 'vi)d',
end: ['test(|)'],
endMode: Mode.Normal,
});
newTest({
title: 'Can do vi) on a matching parenthesis from outside parathesis for multiple lines',
start: ['|test(test)', 'test(test)'],
keysPressed: 'vi)d',
end: ['test(|)', 'test(test)'],
endMode: Mode.Normal,
});
newTest({
title: 'Can do vi) on multiple matching parens',
start: ['test(te(te|st)st)'],
@ -711,6 +751,14 @@ suite('Mode Visual', () => {
endMode: Mode.Normal,
});
newTest({
title: 'Can do va) on a matching parenthesis from outside parenthesis',
start: ['|test(test);'],
keysPressed: 'va)d',
end: ['test|;'],
endMode: Mode.Normal,
});
newTest({
title: 'Can do va) on multiple matching parens',
start: ['test(te(te|st)st);'],