MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / highlight

Function highlight

source code/components/VirtualMessageList.tsx:483–527  ·  view source on GitHub ↗
(ord: number)

Source from the content-addressed store, hash-verified

481 // scrollTop fresh. If ord's position is off-viewport, scroll to bring
482 // it in, recompute rowOffset. setPositions triggers overlay write.
483 function highlight(ord: number): void {
484 const s = scrollRef.current;
485 const {
486 msgIdx,
487 positions
488 } = elementPositions.current;
489 if (!s || positions.length === 0 || msgIdx < 0) {
490 setPositions?.(null);
491 return;
492 }
493 const idx = Math.max(0, Math.min(ord, positions.length - 1));
494 const p = positions[idx]!;
495 const top = jumpState.current.getItemTop(msgIdx);
496 // lo = item's position within scroll content (wrapper-relative).
497 // viewportTop = where the scroll content starts on SCREEN (after
498 // ScrollBox padding/border + any chrome above). Highlight writes to
499 // screen-absolute, so rowOffset = viewportTop + lo. Observed: off-by-
500 // 1+ without viewportTop (FullscreenLayout has paddingTop=1 on the
501 // ScrollBox, plus any header above).
502 const vpTop = s.getViewportTop();
503 let lo = top - s.getScrollTop();
504 const vp = s.getViewportHeight();
505 let screenRow = vpTop + lo + p.row;
506 // Off viewport → scroll to bring it in (HEADROOM from top).
507 // scrollTo commits sync; read-back after gives fresh lo.
508 if (screenRow < vpTop || screenRow >= vpTop + vp) {
509 s.scrollTo(Math.max(0, top + p.row - HEADROOM));
510 lo = top - s.getScrollTop();
511 screenRow = vpTop + lo + p.row;
512 }
513 setPositions?.({
514 positions,
515 rowOffset: vpTop + lo,
516 currentIdx: idx
517 });
518 // Badge: global current = sum of occurrences before this msg + ord+1.
519 // prefixSum[ptr] is engine-counted (indexOf on extractSearchText);
520 // may drift from render-count for ghost messages but close enough —
521 // badge is a rough location hint, not a proof.
522 const st = searchState.current;
523 const total = st.prefixSum.at(-1) ?? 0;
524 const current = (st.prefixSum[st.ptr] ?? 0) + idx + 1;
525 onSearchMatchesChange?.(total, current);
526 logForDebugging(`highlight(i=${msgIdx}, ord=${idx}/${positions.length}): ` + `pos={row:${p.row},col:${p.col}} lo=${lo} screenRow=${screenRow} ` + `badge=${current}/${total}`);
527 }
528 highlightRef.current = highlight;
529
530 // Seek effect. jump() sets scanRequestRef + scrollToIndex + bump.

Callers 1

stepFunction · 0.85

Calls 2

logForDebuggingFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected