@@ -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