@@ -478,7 +478,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
478478 const searchContents : WorkspaceSearchIndex [ "Service" ] [ "searchContents" ] = Effect . fn (
479479 "WorkspaceSearchIndex.searchContents" ,
480480 ) ( function * ( input ) {
481- const { searchQuery, regexMode } = buildContentSearchQuery ( input ) ;
481+ let { searchQuery, regexMode } = buildContentSearchQuery ( input ) ;
482482 const deadline = performance . now ( ) + CONTENT_SEARCH_TIME_BUDGET_MS ;
483483 // Grep cursors advance per file; whole-word filtering needs enough raw candidates before advancing.
484484 const rawPageSize = input . wholeWord
@@ -487,6 +487,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
487487 const matches : Array < ProjectSearchContentsResult [ "matches" ] [ number ] > = [ ] ;
488488 let nextCursor : GrepCursor | null = null ;
489489 let regexFallbackError : string | undefined ;
490+ let retryLiterally = false ;
490491
491492 do {
492493 const remainingTimeBudgetMs = Math . max ( 1 , Math . ceil ( deadline - performance . now ( ) ) ) ;
@@ -500,6 +501,13 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
500501 timeBudgetMs : remainingTimeBudgetMs ,
501502 } ) ,
502503 ) ;
504+ // fff searches an invalid pattern as a literal, which would keep the `(?i)` prefix.
505+ retryLiterally = regexMode && ! input . caseSensitive && result . regexFallbackError !== undefined ;
506+ if ( retryLiterally ) {
507+ regexFallbackError = result . regexFallbackError ;
508+ ( { searchQuery, regexMode } = buildContentSearchQuery ( { ...input , useRegex : false } ) ) ;
509+ continue ;
510+ }
503511
504512 for ( const match of result . items ) {
505513 const matchRanges = mapContentMatchRanges ( match . lineContent , match . matchRanges ) . filter (
@@ -516,7 +524,10 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
516524 }
517525 nextCursor = result . nextCursor ;
518526 regexFallbackError ??= result . regexFallbackError ;
519- } while ( matches . length < input . limit && nextCursor !== null && performance . now ( ) < deadline ) ;
527+ } while (
528+ retryLiterally ||
529+ ( matches . length < input . limit && nextCursor !== null && performance . now ( ) < deadline )
530+ ) ;
520531
521532 return {
522533 matches : matches . slice ( 0 , input . limit ) ,
0 commit comments