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

Function StickyTracker

source code/components/VirtualMessageList.tsx:894–1083  ·  view source on GitHub ↗

* Effect-only child that tracks the last user-prompt scrolled above the * viewport top and fires onChange when it changes. * * Rendered as a separate component (not a hook in VirtualMessageList) so it * can subscribe to scroll at FINER granularity than SCROLL_QUANTUM=40. The * list needs the co

({
  messages,
  start,
  end,
  offsets,
  getItemTop,
  getItemElement,
  scrollRef
}: {
  messages: RenderableMessage[];
  start: number;
  end: number;
  offsets: ArrayLike<number>;
  getItemTop: (index: number) => number;
  getItemElement: (index: number) => DOMElement | null;
  scrollRef: RefObject<ScrollBoxHandle | null>;
})

Source from the content-addressed store, hash-verified

892 * from the mount-range end; break when an item's top is above target.
893 */
894function StickyTracker({
895 messages,
896 start,
897 end,
898 offsets,
899 getItemTop,
900 getItemElement,
901 scrollRef
902}: {
903 messages: RenderableMessage[];
904 start: number;
905 end: number;
906 offsets: ArrayLike<number>;
907 getItemTop: (index: number) => number;
908 getItemElement: (index: number) => DOMElement | null;
909 scrollRef: RefObject<ScrollBoxHandle | null>;
910}): null {
911 const {
912 setStickyPrompt
913 } = useContext(ScrollChromeContext);
914 // Fine-grained subscription — snapshot is unquantized scrollTop+delta so
915 // every scroll action (wheel tick, PgUp, drag) triggers a re-render of
916 // THIS component only. Sticky bit folded into the sign so sticky→broken
917 // also triggers (scrollToBottom sets sticky without moving scrollTop).
918 const subscribe = useCallback((listener: () => void) => scrollRef.current?.subscribe(listener) ?? NOOP_UNSUB, [scrollRef]);
919 useSyncExternalStore(subscribe, () => {
920 const s = scrollRef.current;
921 if (!s) return NaN;
922 const t = s.getScrollTop() + s.getPendingDelta();
923 return s.isSticky() ? -1 - t : t;
924 });
925
926 // Read live scroll state on every render.
927 const isSticky = scrollRef.current?.isSticky() ?? true;
928 const target = Math.max(0, (scrollRef.current?.getScrollTop() ?? 0) + (scrollRef.current?.getPendingDelta() ?? 0));
929
930 // Walk the mounted range to find the first item at-or-below the viewport
931 // top. `range` is from the parent's coarse-quantum render (may be slightly
932 // stale) but overscan guarantees it spans well past the viewport in both
933 // directions. Items without a Yoga layout yet (newly mounted this frame)
934 // are treated as at-or-below — they're somewhere in view, and assuming
935 // otherwise would show a sticky for a prompt that's actually on screen.
936 let firstVisible = start;
937 let firstVisibleTop = -1;
938 for (let i = end - 1; i >= start; i--) {
939 const top = getItemTop(i);
940 if (top >= 0) {
941 if (top < target) break;
942 firstVisibleTop = top;
943 }
944 firstVisible = i;
945 }
946 let idx = -1;
947 let text: string | null = null;
948 if (firstVisible > 0 && !isSticky) {
949 for (let i = firstVisible - 1; i >= 0; i--) {
950 const t = stickyPromptText(messages[i]!);
951 if (t === null) continue;

Callers

nothing calls this directly

Calls 3

stickyPromptTextFunction · 0.85
maxMethod · 0.80
searchMethod · 0.80

Tested by

no test coverage detected