Skip to content

Commit 4137b4e

Browse files
committed
Fix that ViFindBrace doesn't search for brace when current char is not a brace
1 parent a7d988f commit 4137b4e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

PSReadLine/Movement.vi.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,32 @@ private int ViFindBrace(int i)
254254
case ')':
255255
return ViFindBackward(i, '(', withoutPassing: ')');
256256
default:
257-
return i;
257+
int l1 = ViFindForward(i, '{', withoutPassing: '}') is var x && x > i ? x : int.MaxValue;
258+
int l2 = ViFindForward(i, '[', withoutPassing: ']') is var y && y > i ? y : int.MaxValue;
259+
int l3 = ViFindForward(i, '(', withoutPassing: ')') is var z && z > i ? z : int.MaxValue;
260+
int r1 = ViFindForward(i, '}', withoutPassing: '{') is var a && a > i ? a : int.MaxValue;
261+
int r2 = ViFindForward(i, ']', withoutPassing: '[') is var b && b > i ? b : int.MaxValue;
262+
int r3 = ViFindForward(i, ')', withoutPassing: '(') is var c && c > i ? c : int.MaxValue;
263+
int closestLeft = Math.Min(Math.Min(l1, l2), l3);
264+
int closestRight = Math.Min(Math.Min(r1, r2), r3);
265+
266+
if (closestRight <= closestLeft && closestRight != int.MaxValue)
267+
{
268+
return closestRight;
269+
}
270+
271+
closestLeft = closestLeft == int.MaxValue ? i : closestLeft;
272+
switch (_buffer[closestLeft])
273+
{
274+
case '{':
275+
return ViFindForward(closestLeft, '}', withoutPassing: '{');
276+
case '[':
277+
return ViFindForward(closestLeft, ']', withoutPassing: '[');
278+
case '(':
279+
return ViFindForward(closestLeft, ')', withoutPassing: '(');
280+
default:
281+
return i;
282+
}
258283
}
259284
}
260285

0 commit comments

Comments
 (0)