Skip to content

Commit c09cc58

Browse files
committed
fix: improve autoscroll behavior for thinking sections
- Add smart autoscroll detection for reasoning/thinking messages - Preserve user scroll position when manually scrolling up during thinking - Resume autoscroll when user scrolls back to bottom - Fixes issue where thinking content was unreadable due to constant scrolling Fixes #7879
1 parent 8fee312 commit c09cc58

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
14191419
}
14201420
}, [])
14211421

1422+
// Track if we're currently streaming a thinking/reasoning message
1423+
const isStreamingThinking = useMemo(() => {
1424+
const lastMessage = modifiedMessages.at(-1)
1425+
return lastMessage?.say === "reasoning" && lastMessage?.partial === true
1426+
}, [modifiedMessages])
1427+
1428+
// Enhanced scroll behavior for thinking sections
1429+
useEffect(() => {
1430+
// When streaming thinking content, check if user has manually scrolled
1431+
// If they haven't, continue auto-scrolling
1432+
// If they have (disableAutoScrollRef.current is true), respect their choice
1433+
if (isStreamingThinking && !disableAutoScrollRef.current) {
1434+
// Continue auto-scrolling for thinking content if user hasn't intervened
1435+
scrollToBottomSmooth()
1436+
}
1437+
}, [isStreamingThinking, scrollToBottomSmooth])
1438+
14221439
useEvent("wheel", handleWheel, window, { passive: true }) // passive improves scrolling performance
14231440

14241441
// Effect to handle showing the checkpoint warning after a delay
@@ -1903,6 +1920,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
19031920
atBottomStateChange={(isAtBottom: boolean) => {
19041921
setIsAtBottom(isAtBottom)
19051922
if (isAtBottom) {
1923+
// Re-enable autoscroll when user scrolls to bottom
1924+
// This is the key fix: users can scroll up to read thinking content,
1925+
// and autoscroll resumes when they scroll back down
19061926
disableAutoScrollRef.current = false
19071927
}
19081928
setShowScrollToBottom(disableAutoScrollRef.current && !isAtBottom)

0 commit comments

Comments
 (0)