Fix % movement when not on opening character (#490)

Vim's behavior is to move to the closing match, if available. Prior to
this commit, we were moving to the opening char.

Fixes #480
This commit is contained in:
Aiden Scandella 2016-07-20 23:17:44 -07:00 committed by Jason Poon
parent 453575dde6
commit 507741c9fd
2 changed files with 17 additions and 1 deletions

View File

@ -2224,7 +2224,9 @@ class MoveToMatchingBracket extends BaseMovement {
for (let i = position.character; i < text.length; i++) {
if (PairMatcher.pairings[text[i]]) {
return new Position(position.line, i);
// We found an opening char, now move to the matching closing char
const openPosition = new Position(position.line, i);
return PairMatcher.nextPairedChar(openPosition, text[i], true);
}
}

View File

@ -43,6 +43,20 @@ suite("Mode Normal", () => {
end: ["((( ))|)"],
});
newTest({
title: "Can handle % before opening brace",
start: ['|one (two)'],
keysPressed: '%',
end: ["one (two|)"],
});
newTest({
title: "Can handle % nested inside parens",
start: ['(|one { two })'],
keysPressed: '%',
end: ["(one { two |})"],
});
newTest({
title: "Can handle dw",
start: ['one |two three'],