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

Function step

source code/components/VirtualMessageList.tsx:652–696  ·  view source on GitHub ↗
(delta: 1 | -1)

Source from the content-addressed store, hash-verified

650 // jump) triggers auto-advance from scan-effect. Wraparound guard stops
651 // if every message is a phantom.
652 function step(delta: 1 | -1): void {
653 const st = searchState.current;
654 const {
655 matches,
656 prefixSum
657 } = st;
658 const total = prefixSum.at(-1) ?? 0;
659 if (matches.length === 0) return;
660
661 // Seek in-flight — queue this press (one-deep, latest overwrites).
662 // The seek effect fires it after highlight.
663 if (scanRequestRef.current) {
664 pendingStepRef.current = delta;
665 return;
666 }
667 if (startPtrRef.current < 0) startPtrRef.current = st.ptr;
668 const {
669 positions
670 } = elementPositions.current;
671 const newOrd = st.screenOrd + delta;
672 if (newOrd >= 0 && newOrd < positions.length) {
673 st.screenOrd = newOrd;
674 highlight(newOrd); // updates badge internally
675 startPtrRef.current = -1;
676 return;
677 }
678
679 // Exhausted visible. Advance ptr → jump → re-scan.
680 const ptr = (st.ptr + delta + matches.length) % matches.length;
681 if (ptr === startPtrRef.current) {
682 setPositions?.(null);
683 startPtrRef.current = -1;
684 logForDebugging(`step: wraparound at ptr=${ptr}, all ${matches.length} msgs phantoms`);
685 return;
686 }
687 st.ptr = ptr;
688 st.screenOrd = 0; // resolved after scan (wantLast → length-1)
689 jump(matches[ptr]!, delta < 0);
690 // screenOrd will resolve after scan. Best-effort: prefixSum[ptr] + 0
691 // for n (first pos), prefixSum[ptr+1] for N (last pos = count-1).
692 // The scan-effect's highlight will be the real value; this is a
693 // pre-scan placeholder so the badge updates immediately.
694 const placeholder = delta < 0 ? prefixSum[ptr + 1] ?? total : prefixSum[ptr]! + 1;
695 onSearchMatchesChange?.(total, placeholder);
696 }
697 stepRef.current = step;
698 useImperativeHandle(jumpRef, () => ({
699 // Non-search jump (sticky header click, etc). No scan, no positions.

Callers 1

VirtualMessageListFunction · 0.70

Calls 3

highlightFunction · 0.85
logForDebuggingFunction · 0.85
jumpFunction · 0.85

Tested by

no test coverage detected