@@ -254,7 +254,29 @@ private int ViFindBrace(int i)
254254 case ')' :
255255 return ViFindBackward ( i , '(' , withoutPassing : ')' ) ;
256256 default :
257- return i ;
257+ ReadOnlySpan < char > parenthese = stackalloc char [ ] { '{' , '}' , '(' , ')' , '[' , ']' } ;
258+ int nextParen = i ;
259+ for ( ; nextParen < _buffer . Length ; nextParen ++ )
260+ {
261+ for ( int idx = 0 ; idx < parenthese . Length ; idx ++ )
262+ if ( parenthese [ idx ] == _buffer [ nextParen ] ) goto Outer ;
263+ }
264+
265+ Outer :
266+ int match = _buffer [ nextParen ] switch
267+ {
268+ // if next is opening, find forward
269+ '{' => ViFindForward ( nextParen , '}' , withoutPassing : '{' ) ,
270+ '[' => ViFindForward ( nextParen , ']' , withoutPassing : '[' ) ,
271+ '(' => ViFindForward ( nextParen , ')' , withoutPassing : '(' ) ,
272+ // if next is closing, find backward
273+ '}' => ViFindBackward ( nextParen , '}' , withoutPassing : '}' ) ,
274+ ']' => ViFindBackward ( nextParen , '[' , withoutPassing : ']' ) ,
275+ ')' => ViFindBackward ( nextParen , '(' , withoutPassing : ')' ) ,
276+ _ => nextParen
277+ } ;
278+
279+ return match == nextParen ? i : match ;
258280 }
259281 }
260282
0 commit comments