Pause live output follow while reading #3936
Closedlnieuwenhuis(GitHub profile, opens in a new tab)wants to merge 20 commits into
main fromrefs/pull/3936/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/web/src/components/chat/MessagesTimeline.logic.ts line 28OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -16,3 +16,13 @@1616 export const TIMELINE_CONTENT_MAX_WIDTH = 768;1717 export const TIMELINE_MINIMAP_PERSISTENT_GUTTER = 48;181819+export function shouldPauseTimelineAutoFollow({20+ isAtEnd,21+ previousScrollOffset,22+ scrollOffset,23+}: {24+ readonly isAtEnd: boolean | undefined;25+ readonly previousScrollOffset: number | null;26+ readonly scrollOffset: number | null;27+}) {28+ return (
- apps/web/src/components/chat/MessagesTimeline.logic.ts line 97Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -16,3 +16,19 @@1616 export const TIMELINE_CONTENT_MAX_WIDTH = 768;1717 export const TIMELINE_MINIMAP_PERSISTENT_GUTTER = 48;181819+export function shouldPauseTimelineAutoFollow({20+ isAtEnd,21+ previousScrollOffset,22+ scrollOffset,23+}: {24+ readonly isAtEnd: boolean | undefined;25+ readonly previousScrollOffset: number | null;26+ readonly scrollOffset: number | null;27+}) {28+ return (29+ isAtEnd === false &&30+ scrollOffset !== null &&31+ previousScrollOffset !== null &&32+ scrollOffset < previousScrollOffset - 133+ );34+}
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/chat/MessagesTimeline.logic.ts line 73OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -18,0 +41,21 @@41+ isAtEnd,42+ },43+ shouldPause: false,44+ } as const;45+ }46+47+ const shouldPause =48+ isAtEnd === false &&49+ scrollOffset !== null &&50+ state.anchorScrollOffset !== null &&51+ scrollOffset < state.anchorScrollOffset - 1;52+53+ let anchorScrollOffset = shouldPause ? null : state.anchorScrollOffset;54+ if (55+ !shouldPause &&56+ isAtEnd === true &&57+ scrollOffset !== null &&58+ (state.isAtEnd !== true || anchorScrollOffset === null || scrollOffset > anchorScrollOffset)59+ ) {60+ anchorScrollOffset = scrollOffset;61+ }apps/web/src/components/chat/MessagesTimeline.logic.ts line 73OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -18,0 +41,21 @@41+ isAtEnd,42+ },43+ shouldPause: false,44+ } as const;45+ }46+47+ const shouldPause =48+ isAtEnd === false &&49+ scrollOffset !== null &&50+ state.anchorScrollOffset !== null &&51+ scrollOffset < state.anchorScrollOffset - 1;52+53+ let anchorScrollOffset = shouldPause ? null : state.anchorScrollOffset;54+ if (55+ !shouldPause &&56+ isAtEnd === true &&57+ scrollOffset !== null &&58+ (state.isAtEnd !== true || anchorScrollOffset === null || scrollOffset > anchorScrollOffset)59+ ) {60+ anchorScrollOffset = scrollOffset;61+ }
- apps/web/src/components/chat/MessagesTimeline.tsx line 498OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -352,0 +366,21 @@366+ const scrollTop = state?.scroll ?? null;367+ const pendingNavigation = pendingTimelineNavigationRef.current;368+ if (369+ pendingNavigation &&370+ (pendingNavigation.timelineKey !== routeThreadKey || pendingNavigation.expiresAt < Date.now())371+ ) {372+ pendingTimelineNavigationRef.current = null;373+ } else if (374+ pendingNavigation &&375+ scrollTop !== null &&376+ scrollTop !== pendingNavigation.scrollOffset377+ ) {378+ pendingTimelineNavigationRef.current = null;379+ if (380+ timelineUserScrollRequestsPause({381+ inputScrollOffset: pendingNavigation.scrollOffset,382+ scrollOffset: scrollTop,383+ })384+ ) {385+ onManualNavigation();386+ }apps/web/src/components/chat/MessagesTimeline.tsx line 425OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -372,7 +407,19 @@372407 rowTop !== null &&373408 rowTop < scrollBottom &&374- rowTop + Math.max(1, rowHeight ?? 1) > scrollTop;409+ rowTop + Math.max(1, rowHeight ?? 1) > resolvedScrollTop;375410376411 strip.dataset.inView = inView ? "true" : "false";377412 }378- }, [listRef, minimapItems, minimapStripMap, onIsAtEndChange]);413+ }, [listRef, minimapItems, minimapStripMap, onIsAtEndChange, onManualNavigation, routeThreadKey]);414+415+ const armTimelineNavigation = useCallback(() => {416+ const scrollOffset = listRef.current?.getState?.().scroll;417+ if (typeof scrollOffset !== "number") {418+ return;419+ }420+ pendingTimelineNavigationRef.current = {421+ timelineKey: routeThreadKey,422+ scrollOffset,423+ expiresAt: Date.now() + 500,424+ };425+ }, [listRef, routeThreadKey]);apps/web/src/components/chat/MessagesTimeline.tsx line 372OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -350,3 +363,10 @@350363 const handleScroll = useCallback(() => {351364 const state = listRef.current?.getState?.();352365 const isAtEnd = resolveTimelineIsAtEnd(state);366+ const scrollTop = state?.scroll ?? null;367+ const pendingNavigation = pendingTimelineNavigationRef.current;368+ if (369+ pendingNavigation &&370+ (pendingNavigation.timelineKey !== routeThreadKey || pendingNavigation.expiresAt < Date.now())371+ ) {372+ pendingTimelineNavigationRef.current = null;apps/web/src/components/chat/MessagesTimeline.tsx line 498OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -352,0 +366,21 @@366+ const scrollTop = state?.scroll ?? null;367+ const pendingNavigation = pendingTimelineNavigationRef.current;368+ if (369+ pendingNavigation &&370+ (pendingNavigation.timelineKey !== routeThreadKey || pendingNavigation.expiresAt < Date.now())371+ ) {372+ pendingTimelineNavigationRef.current = null;373+ } else if (374+ pendingNavigation &&375+ scrollTop !== null &&376+ scrollTop !== pendingNavigation.scrollOffset377+ ) {378+ pendingTimelineNavigationRef.current = null;379+ if (380+ timelineUserScrollRequestsPause({381+ inputScrollOffset: pendingNavigation.scrollOffset,382+ scrollOffset: scrollTop,383+ })384+ ) {385+ onManualNavigation();386+ }apps/web/src/components/chat/MessagesTimeline.tsx line 498OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -352,0 +366,21 @@366+ const scrollTop = state?.scroll ?? null;367+ const pendingNavigation = pendingTimelineNavigationRef.current;368+ if (369+ pendingNavigation &&370+ (pendingNavigation.timelineKey !== routeThreadKey || pendingNavigation.expiresAt < Date.now())371+ ) {372+ pendingTimelineNavigationRef.current = null;373+ } else if (374+ pendingNavigation &&375+ scrollTop !== null &&376+ scrollTop !== pendingNavigation.scrollOffset377+ ) {378+ pendingTimelineNavigationRef.current = null;379+ if (380+ timelineUserScrollRequestsPause({381+ inputScrollOffset: pendingNavigation.scrollOffset,382+ scrollOffset: scrollTop,383+ })384+ ) {385+ onManualNavigation();386+ }
- apps/web/src/components/chat/MessagesTimeline.logic.ts lines 54 to 54OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -18,0 +34,21 @@34+ input.key === "ArrowUp" ||35+ input.key === "PageUp" ||36+ input.key === "Home" ||37+ (input.key === " " && input.shiftKey)38+ );39+ }40+}41+42+export interface TimelineScrollableNodeState {43+ readonly clientHeight: number;44+ readonly scrollHeight: number;45+ readonly scrollTop: number;46+}47+48+export function resolveTimelineScrollableNodeIsAtEnd(49+ scrollNode: TimelineScrollableNodeState | null | undefined,50+): boolean | undefined {51+ if (!scrollNode) {52+ return undefined;53+ }54+ return scrollNode.scrollHeight - scrollNode.scrollTop - scrollNode.clientHeight <= 0;
- apps/web/src/components/chat/MessagesTimeline.tsx line 382Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -371,4 +393,3 @@371393 const inView =372394 rowTop !== null &&373395 rowTop < scrollBottom &&374- rowTop + Math.max(1, rowHeight ?? 1) > scrollTop;apps/web/src/components/chat/MessagesTimeline.tsx line 616OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -378,0 +448,21 @@448+ })449+ ) {450+ markTimelineManualNavigation();451+ }452+ },453+ [markTimelineManualNavigation],454+ );455+ const handleTimelinePointerDownCapture = useCallback(456+ (event: PointerEvent<HTMLDivElement>) => {457+ const scrollNode = listRef.current?.getScrollableNode();458+ if (!scrollNode || event.target !== scrollNode) {459+ return;460+ }461+ const scrollbarWidth = scrollNode.offsetWidth - scrollNode.clientWidth;462+ if (463+ scrollbarWidth > 0 &&464+ event.clientX < scrollNode.getBoundingClientRect().right - scrollbarWidth465+ ) {466+ return;467+ }468+ markTimelineManualNavigation();
- apps/web/src/components/chat/MessagesTimeline.tsx line 535Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -371,8 +430,17 @@371430 const inView =372431 rowTop !== null &&373432 rowTop < scrollBottom &&374- rowTop + Math.max(1, rowHeight ?? 1) > scrollTop;433+ rowTop + Math.max(1, rowHeight ?? 1) > resolvedScrollTop;375434376435 strip.dataset.inView = inView ? "true" : "false";377436 }378- }, [listRef, minimapItems, minimapStripMap, onIsAtEndChange]);437+ }, [438+ listRef,439+ markTimelineManualNavigation,440+ minimapItems,441+ minimapStripMap,442+ onIsAtEndChange,443+ routeThreadKey,444+ ]);445+446+ const handleTimelineWheelCapture = useCallback(
- apps/web/src/components/chat/MessagesTimeline.logic.ts line 96Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -18,0 +46,21 @@46+}47+48+export function resolveTimelineScrollableNodeIsAtEnd(49+ scrollNode: TimelineScrollableNodeState | null | undefined,50+): boolean | undefined {51+ if (!scrollNode) {52+ return undefined;53+ }54+ return scrollNode.scrollHeight - scrollNode.scrollTop - scrollNode.clientHeight <= 1;55+}56+57+export function timelineManualNavigationReachedEnd({58+ previousScrollTop,59+ scrollTop,60+ isAtEnd,61+}: {62+ readonly previousScrollTop: number;63+ readonly scrollTop: number;64+ readonly isAtEnd: boolean;65+}) {66+ return isAtEnd && scrollTop > previousScrollTop;
- apps/web/src/components/chat/MessagesTimeline.tsx lines 483 to 484OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -378,0 +464,21 @@464+ if (465+ timelineNavigationInputMovesTowardHistory({466+ type: "touch",467+ previousY: timelineTouchYRef.current,468+ currentY,469+ }) &&470+ timelineScrollableNodeCanNavigateTowardHistory(listRef.current?.getScrollableNode())471+ ) {472+ markTimelineManualNavigation();473+ }474+ timelineTouchYRef.current = currentY;475+ },476+ [listRef, markTimelineManualNavigation],477+ );478+ const resetTimelineTouchTracking = useCallback(() => {479+ timelineTouchYRef.current = null;480+ }, []);481+ const handleTimelineKeyDownCapture = useCallback(482+ (event: KeyboardEvent<HTMLDivElement>) => {483+ const target = event.target instanceof HTMLElement ? event.target : null;484+ if (target?.closest("input, textarea, [contenteditable='true']")) {
- apps/web/src/components/chat/MessagesTimeline.tsx line 505OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -378,0 +485,21 @@485+ if (486+ timelineNavigationInputMovesTowardHistory({487+ type: "touch",488+ previousY: timelineTouchYRef.current,489+ currentY,490+ }) &&491+ timelineScrollableNodeCanNavigateTowardHistory(listRef.current?.getScrollableNode())492+ ) {493+ markTimelineManualNavigation();494+ }495+ timelineTouchYRef.current = currentY;496+ },497+ [listRef, markTimelineManualNavigation],498+ );499+ const resetTimelineTouchTracking = useCallback(() => {500+ timelineTouchYRef.current = null;501+ }, []);502+ const handleTimelineKeyDownCapture = useCallback(503+ (event: KeyboardEvent<HTMLDivElement>) => {504+ const target = event.target instanceof HTMLElement ? event.target : null;505+ if (target?.closest(TIMELINE_KEYBOARD_INTERACTIVE_SELECTOR)) {
- apps/web/src/components/chat/MessagesTimeline.tsx line 511OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -378,0 +491,21 @@491+ previousY: timelineTouchYRef.current,492+ currentY,493+ }) &&494+ timelineScrollableNodeCanNavigateTowardHistory(listRef.current?.getScrollableNode())495+ ) {496+ markTimelineManualNavigation();497+ }498+ timelineTouchYRef.current = currentY;499+ },500+ [listRef, markTimelineManualNavigation],501+ );502+ const resetTimelineTouchTracking = useCallback(() => {503+ timelineTouchYRef.current = null;504+ }, []);505+ const handleTimelineKeyDownCapture = useCallback(506+ (event: KeyboardEvent<HTMLDivElement>) => {507+ const target = event.target instanceof HTMLElement ? event.target : null;508+ if (509+ target?.closest(TIMELINE_KEYBOARD_INPUT_SELECTOR) ||510+ (event.key === " " && target?.closest(TIMELINE_KEYBOARD_ACTIVATION_SELECTOR))511+ ) {
- apps/web/src/components/chat/MessagesTimeline.tsx line 506OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -378,0 +486,21 @@486+ type: "keyboard",487+ key: event.key,488+ shiftKey: event.shiftKey,489+ })490+ ) {491+ return;492+ }493+ const scrollNode = listRef.current?.getScrollableNode();494+ if (!scrollNode || !timelineScrollableNodeCanNavigateTowardHistory(scrollNode)) {495+ return;496+ }497+ if (keyboardNavigationFrameRef.current !== null) {498+ cancelAnimationFrame(keyboardNavigationFrameRef.current);499+ }500+ const scrollTop = scrollNode.scrollTop;501+ keyboardNavigationFrameRef.current = requestAnimationFrame(() => {502+ keyboardNavigationFrameRef.current = null;503+ if (scrollNode.scrollTop < scrollTop) {504+ markTimelineManualNavigation();505+ }506+ });
lnieuwenhuis(GitHub profile, opens in a new tab) closed this
lnieuwenhuis(GitHub profile, opens in a new tab) reopened this
- apps/web/src/components/ChatView.tsx line 3505OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -3530,6 +3500,6 @@35303500 setShowScrollToBottom(false);35313501 return;35323502 }3533- if (isAtEndRef.current === isAtEnd) return;3534- isAtEndRef.current = isAtEnd;35353503 if (isAtEnd) {3504+ isAtEndRef.current = true;3505+ setTimelineAutoFollowEnabled(true);
- apps/web/src/components/chat/MessagesTimeline.tsx line 569Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -383,0 +474,21 @@474+ );475+ const handleTimelineTouchStartCapture = useCallback((event: TouchEvent<HTMLDivElement>) => {476+ timelineTouchYRef.current = event.touches[0]?.clientY ?? null;477+ }, []);478+ const handleTimelineTouchMoveCapture = useCallback(479+ (event: TouchEvent<HTMLDivElement>) => {480+ const currentY = event.touches[0]?.clientY ?? null;481+ if (482+ timelineNavigationInputMovesTowardHistory({483+ type: "touch",484+ previousY: timelineTouchYRef.current,485+ currentY,486+ }) &&487+ timelineScrollableNodeCanNavigateTowardHistory(listRef.current?.getScrollableNode())488+ ) {489+ markTimelineManualNavigation();490+ }491+ timelineTouchYRef.current = currentY;492+ },493+ [listRef, markTimelineManualNavigation],494+ );apps/web/src/components/chat/MessagesTimeline.logic.ts line 85Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -18,0 +43,21 @@43+ readonly clientHeight: number;44+ readonly scrollHeight: number;45+ readonly scrollTop: number;46+}47+48+export function timelineScrollableNodeCanNavigateTowardHistory(49+ scrollNode: TimelineScrollableNodeState | null | undefined,50+): boolean {51+ return Boolean(52+ scrollNode && scrollNode.scrollHeight > scrollNode.clientHeight && scrollNode.scrollTop > 0,53+ );54+}55+56+export function resolveTimelineScrollableNodeIsAtEnd(57+ scrollNode: TimelineScrollableNodeState | null | undefined,58+): boolean | undefined {59+ if (!scrollNode) {60+ return undefined;61+ }62+ return scrollNode.scrollHeight - scrollNode.scrollTop - scrollNode.clientHeight <= 1;63+}
- apps/web/src/components/chat/MessagesTimeline.logic.ts line 67OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -18,0 +47,21 @@47+48+export function timelineScrollableNodeCanNavigateTowardHistory(49+ scrollNode: TimelineScrollableNodeState | null | undefined,50+): boolean {51+ return Boolean(52+ scrollNode && scrollNode.scrollHeight > scrollNode.clientHeight && scrollNode.scrollTop > 0,53+ );54+}55+56+export function resolveTimelineScrollableNodeIsAtEnd(57+ scrollNode: TimelineScrollableNodeState | null | undefined,58+ contentInsetEndAdjustment = 0,59+): boolean | undefined {60+ if (!scrollNode) {61+ return undefined;62+ }63+ const endThreshold = Math.max(64+ 1,65+ Number.isFinite(contentInsetEndAdjustment) ? contentInsetEndAdjustment : 0,66+ );67+ return scrollNode.scrollHeight - scrollNode.scrollTop - scrollNode.clientHeight <= endThreshold;
- apps/web/src/components/chat/MessagesTimeline.tsx line 398Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -352,3 +381,13 @@352381 : undefined;353382 }, [anchorMessageId, handleAnchorReady, handleAnchorSizeChanged, rows]);354383384+ const markTimelineManualNavigation = useCallback(() => {385+ if (manualNavigationRef.current?.timelineKey !== routeThreadKey) {386+ const scrollTop = listRef.current?.getScrollableNode()?.scrollTop;387+ if (typeof scrollTop !== "number") {388+ return;389+ }390+ manualNavigationRef.current = { timelineKey: routeThreadKey, scrollTop };391+ }392+ onManualNavigation();393+ }, [listRef, onManualNavigation, routeThreadKey]);apps/web/src/components/chat/MessagesTimeline.tsx line 501Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -358,2 +476,20 @@476+ manualNavigation &&477+ scrollTop !== null &&478+ timelineManualNavigationReachedEnd({479+ previousScrollTop: manualNavigation.scrollTop,480+ scrollTop,481+ isAtEnd: scrollNodeIsAtEnd,482+ }),483+ );484+ const isAtEnd =485+ manualNavigation && scrollTop !== null486+ ? manualNavigationReachedEnd487+ : resolveTimelineIsAtEnd(state);488+ if (manualNavigation && scrollTop !== null) {489+ manualNavigation.scrollTop = scrollTop;490+ if (isAtEnd) {491+ manualNavigationRef.current = null;492+ }493+ }358494 if (isAtEnd !== undefined) {359- onIsAtEndChange(isAtEnd);495+ onIsAtEndChange({ isAtEnd, manualNavigationReachedEnd });
- apps/web/src/components/ChatView.tsx line 3622Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -3613,3 +3608,4 @@36133608 useEffect(() => {36143609 setPullRequestDialogState(null);36153610 isAtEndRef.current = true;3611+ setTimelineAutoFollowEnabled(true);apps/web/src/components/chat/MessagesTimeline.tsx line 791OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -521,4 +788,4 @@521788 hitStripWidth={minimapHitStripWidth}522789 stripMap={minimapStripMap}523790 onSelect={(item) => {524- onManualNavigation();791+ markTimelineManualNavigation();
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/components/chat/MessagesTimeline.tsx line 627Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -386,0 +604,21 @@604+ }605+ pointerNavigationRef.current = {606+ pointerId: event.pointerId,607+ timelineKey: routeThreadKey,608+ scrollTop: scrollNode.scrollTop,609+ };610+ },611+ [listRef, routeThreadKey],612+ );613+ const handleTimelineMinimapSelect = useCallback(614+ (item: TimelineMinimapItem) => {615+ flushSync(() => setNavigationProbeTimelineKey(routeThreadKey));616+ markTimelineManualNavigation();617+ void listRef.current?.scrollToIndex({618+ index: item.rowIndex,619+ animated: true,620+ viewOffset: 24,621+ });622+ },623+ [listRef, markTimelineManualNavigation, routeThreadKey],624+ );
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
0931e55a-cabb-4340-86b5-8f0248343781You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share