Skip to content

Fix that ViFindBrace doesn't search for brace when current char is not a brace #4862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion PSReadLine/Movement.vi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,32 @@ private int ViFindBrace(int i)
case ')':
return ViFindBackward(i, '(', withoutPassing: ')');
default:
return i;
int l1 = ViFindForward(i, '{', withoutPassing: '}') is var x && x > i ? x : int.MaxValue;
int l2 = ViFindForward(i, '[', withoutPassing: ']') is var y && y > i ? y : int.MaxValue;
int l3 = ViFindForward(i, '(', withoutPassing: ')') is var z && z > i ? z : int.MaxValue;
int r1 = ViFindForward(i, '}', withoutPassing: '{') is var a && a > i ? a : int.MaxValue;
int r2 = ViFindForward(i, ']', withoutPassing: '[') is var b && b > i ? b : int.MaxValue;
int r3 = ViFindForward(i, ')', withoutPassing: '(') is var c && c > i ? c : int.MaxValue;
int closestLeft = Math.Min(Math.Min(l1, l2), l3);
int closestRight = Math.Min(Math.Min(r1, r2), r3);

if (closestRight <= closestLeft && closestRight != int.MaxValue)
{
return closestRight;
}

closestLeft = closestLeft == int.MaxValue ? i : closestLeft;
switch (_buffer[closestLeft])
{
case '{':
return ViFindForward(closestLeft, '}', withoutPassing: '{');
case '[':
return ViFindForward(closestLeft, ']', withoutPassing: '[');
case '(':
return ViFindForward(closestLeft, ')', withoutPassing: '(');
default:
return i;
}
}
}

Expand Down