@@ -19,6 +19,7 @@ import { useEffect, useRef, useState } from 'react'
19
19
import AnsiUp from 'ansi_up'
20
20
import DOMPurify from 'dompurify'
21
21
import { ANSI_UP_REGEX , ComponentSizeType } from '@Shared/constants'
22
+ import { escapeRegExp } from '@Shared/Helpers'
22
23
import {
23
24
Progressing ,
24
25
Host ,
@@ -197,19 +198,21 @@ export const LogsRenderer = ({
197
198
// We will remove color through [0m and add background color of y6, till searchKey is present and then revert back to original color
198
199
// While reverting if index is 0, would not add any escape code since it is the start of the log
199
200
if ( targetSearchKey && areStagesAvailable ) {
201
+ // Search is working on assumption that color codes are not nested for words.
200
202
const logParts = log . split ( ANSI_UP_REGEX )
201
- const availableEscapeCodes = log . match ( ANSI_UP_REGEX )
203
+ const availableEscapeCodes = log . match ( ANSI_UP_REGEX ) || [ ]
204
+ const searchRegex = new RegExp ( `(${ escapeRegExp ( targetSearchKey ) } )` , 'g' )
202
205
const parts = logParts . reduce ( ( acc , part , index ) => {
203
206
try {
207
+ // Question: Can we directly set it as true inside the replace function?
208
+ isSearchKeyPresent = isSearchKeyPresent || searchRegex . test ( part )
204
209
acc . push (
205
210
part . replace (
206
- new RegExp ( targetSearchKey , 'g' ) ,
207
- `\x1B[0m\x1B[48;2;197;141;54m${ targetSearchKey } \x1B[0m${ index > 0 ? availableEscapeCodes [ index - 1 ] : '' } ` ,
211
+ searchRegex ,
212
+ ( match ) =>
213
+ `\x1B[0m\x1B[48;2;197;141;54m${ match } \x1B[0m${ index > 0 ? availableEscapeCodes [ index - 1 ] : '' } ` ,
208
214
) ,
209
215
)
210
- if ( part . includes ( targetSearchKey ) ) {
211
- isSearchKeyPresent = true
212
- }
213
216
} catch ( searchRegexError ) {
214
217
acc . push ( part )
215
218
}
0 commit comments