File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -304,22 +304,36 @@ static inline TSNode ts_node__first_child_for_byte(
304304 TSNode node = self ;
305305 bool did_descend = true;
306306
307+ NodeChildIterator last_iterator ;
308+ bool has_last_iterator = false;
309+
307310 while (did_descend ) {
308311 did_descend = false;
309312
310313 TSNode child ;
311314 NodeChildIterator iterator = ts_node_iterate_children (& node );
315+ loop :
312316 while (ts_node_child_iterator_next (& iterator , & child )) {
313317 if (ts_node_end_byte (child ) > goal ) {
314318 if (ts_node__is_relevant (child , include_anonymous )) {
315319 return child ;
316320 } else if (ts_node_child_count (child ) > 0 ) {
321+ if (iterator .child_index < ts_subtree_child_count (ts_node__subtree (child ))) {
322+ last_iterator = iterator ;
323+ has_last_iterator = true;
324+ }
317325 did_descend = true;
318326 node = child ;
319327 break ;
320328 }
321329 }
322330 }
331+
332+ if (!did_descend && has_last_iterator ) {
333+ iterator = last_iterator ;
334+ has_last_iterator = false;
335+ goto loop ;
336+ }
323337 }
324338
325339 return ts_node__null ();
You can’t perform that action at this time.
0 commit comments