@@ -470,6 +470,7 @@ export class CodeMirror {
470470 type CM5Result = { from : Pos , to : Pos , match : string [ ] } | null ;
471471 var last : CM6Result = null ;
472472 var lastCM5Result : CM5Result = null ;
473+ var afterEmptyMatch = false ;
473474
474475 if ( pos . ch == undefined ) pos . ch = Number . MAX_VALUE ;
475476 var firstOffset = indexFromPos ( cm . cm6 . state . doc , pos ) ;
@@ -507,17 +508,18 @@ export class CodeMirror {
507508 find : function ( back ?: boolean ) : string [ ] | null | undefined {
508509 var doc = cm . cm6 . state . doc
509510 if ( back ) {
510- let endAt = last ? ( last . from == last . to ? last . to - 1 : last . from ) : firstOffset
511+ let endAt = last ? ( afterEmptyMatch ? last . to - 1 : last . from ) : firstOffset
511512 last = prevMatchInRange ( 0 , endAt ) ;
512513 } else {
513- let startFrom = last ? ( last . from == last . to ? last . to + 1 : last . to ) : firstOffset
514+ let startFrom = last ? ( afterEmptyMatch ? last . to + 1 : last . to ) : firstOffset
514515 last = nextMatch ( startFrom )
515516 }
516517 lastCM5Result = last && {
517518 from : posFromIndex ( doc , last . from ) ,
518519 to : posFromIndex ( doc , last . to ) ,
519520 match : last . match ,
520521 }
522+ afterEmptyMatch = last ? last . from == last . to : false ;
521523 return last && last . match
522524 } ,
523525 from : function ( ) { return lastCM5Result ?. from } ,
0 commit comments