@@ -205,8 +205,10 @@ const LogsRenderer = ({
205205
206206 function createMarkup ( {
207207 log,
208- useCurrentSelectionColor = false ,
208+ currentIndex = - 1 ,
209209 targetSearchKey = searchKey ,
210+ searchMatchResults = null ,
211+ searchIndex = '' ,
210212 } : CreateMarkupPropsType ) : CreateMarkupReturnType {
211213 let isSearchKeyPresent = false
212214 try {
@@ -226,11 +228,12 @@ const LogsRenderer = ({
226228 // Question: Can we directly set it as true inside the replace function?
227229 isSearchKeyPresent = isSearchKeyPresent || searchRegex . test ( part )
228230 acc . push (
229- part . replace (
230- searchRegex ,
231- ( match ) =>
232- `\x1B[0m\x1B[48;2;${ useCurrentSelectionColor ? '0;102;204' : '197;141;54' } m${ match } \x1B[0m${ index > 0 ? availableEscapeCodes [ index - 1 ] : '' } ` ,
233- ) ,
231+ part . replace ( searchRegex , ( match ) => {
232+ if ( searchIndex ) {
233+ searchMatchResults ?. push ( searchIndex )
234+ }
235+ return `\x1B[0m\x1B[48;2;${ searchMatchResults && currentIndex === searchMatchResults . length - 1 ? '0;102;204' : '197;141;54' } m${ match } \x1B[0m${ index > 0 ? availableEscapeCodes [ index - 1 ] : '' } `
236+ } ) ,
234237 )
235238 } catch {
236239 acc . push ( part )
@@ -360,16 +363,22 @@ const LogsRenderer = ({
360363 // Ideally in case of parallel build should receive stage name with logs
361364 // NOTE: For now would always append log to last stage, can show a loader on stage tiles till processed
362365 if ( acc . length > 0 ) {
366+ const lastStage = acc [ acc . length - 1 ]
367+
368+ const searchIndex = getLogSearchIndex ( {
369+ stageIndex : acc . length - 1 ,
370+ lineNumberInsideStage : lastStage . logs . length ,
371+ } )
372+
363373 // In case targetSearchKey is not present createMarkup will internally fallback to searchKey
364374 const { __html, isSearchKeyPresent } = createMarkup ( {
365375 log : streamItem ,
366- // NOTE: the last matched search result was added to the searchMatchResults list
367- // therefore if currentSearchIndex matches it's length then paint it blue if searchKey is present
368- useCurrentSelectionColor : currentIndex === searchMatchResults . length ,
376+ currentIndex,
377+ searchMatchResults,
369378 targetSearchKey,
379+ searchIndex,
370380 } )
371381
372- const lastStage = acc [ acc . length - 1 ]
373382 lastStage . logs . push ( __html )
374383 if ( isSearchKeyPresent ) {
375384 lastStage . isOpen = getIsStageOpen (
@@ -384,13 +393,6 @@ const LogsRenderer = ({
384393 }
385394
386395 searchKeyStatusMap [ lastStage . stage ] [ lastStage . startTime ] = true
387-
388- searchMatchResults . push (
389- getLogSearchIndex ( {
390- stageIndex : acc . length - 1 ,
391- lineNumberInsideStage : lastStage . logs . length - 1 ,
392- } ) ,
393- )
394396 }
395397 }
396398
0 commit comments