Skip to content

Commit f858676

Browse files
committed
ChatView: broaden sticky-disable triggers, keep showScrollToBottom in sync, and hide button flash when engaging sticky follow (#8999)
1 parent 27cb8ae commit f858676

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
14061406
}, [])
14071407
useEvent("wheel", handleWheel, window, { passive: true })
14081408

1409+
// Also disable sticky follow when the chat container is scrolled away from bottom
1410+
useEffect(() => {
1411+
const el = scrollContainerRef.current
1412+
if (!el) return
1413+
const onScroll = () => {
1414+
// Consider near-bottom within a small threshold consistent with Virtuoso settings
1415+
const nearBottom = Math.abs(el.scrollHeight - el.scrollTop - el.clientHeight) < 10
1416+
if (!nearBottom) {
1417+
stickyFollowRef.current = false
1418+
}
1419+
// Keep UI button state in sync with scroll position
1420+
setShowScrollToBottom(!nearBottom)
1421+
}
1422+
el.addEventListener("scroll", onScroll, { passive: true })
1423+
return () => el.removeEventListener("scroll", onScroll)
1424+
}, [])
1425+
14091426
// Effect to clear checkpoint warning when messages appear or task changes
14101427
useEffect(() => {
14111428
if (isHidden || !task) {
@@ -1855,12 +1872,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
18551872
followOutput="smooth"
18561873
atBottomStateChange={(isAtBottom: boolean) => {
18571874
setIsAtBottom(isAtBottom)
1875+
setShowScrollToBottom(!isAtBottom)
18581876
if (!isAtBottom && stickyFollowRef.current) {
18591877
// While in sticky mode, force-pin as streaming increases height
18601878
scrollToBottomAuto()
1861-
return
18621879
}
1863-
setShowScrollToBottom(!isAtBottom)
18641880
}}
18651881
atBottomThreshold={10}
18661882
initialTopMostItemIndex={groupedMessages.length - 1}
@@ -1885,6 +1901,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
18851901
stickyFollowRef.current = true
18861902
// Pin immediately to avoid lag during fast streaming
18871903
scrollToBottomAuto()
1904+
// Hide button immediately to prevent flash
1905+
setShowScrollToBottom(false)
18881906
}}>
18891907
<span className="codicon codicon-chevron-down"></span>
18901908
</VSCodeButton>

0 commit comments

Comments
 (0)