mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Fix scroll-up during streaming not disabling auto-follow
This commit is contained in:
1 parent
494d2907fa
commit
6c514120c3
1 file changed
+8
-9
@@ -19,13 +19,13 @@ export function useAutoScroll({
|
||||
dependency,
|
||||
onScrollStateChange
|
||||
}: UseAutoScrollOptions): UseAutoScrollReturn {
|
||||
const userScrolledUpRef = useRef(false)
|
||||
const isFollowingRef = useRef(true)
|
||||
const isProgrammaticScrollRef = useRef(false)
|
||||
|
||||
const scrollToBottom = useCallback(() => {
|
||||
if (!containerRef?.current) return
|
||||
isProgrammaticScrollRef.current = true
|
||||
containerRef.current.scrollTop = containerRef.current.scrollHeight
|
||||
userScrolledUpRef.current = false
|
||||
isFollowingRef.current = true
|
||||
onScrollStateChange?.(false)
|
||||
}, [containerRef, onScrollStateChange])
|
||||
@@ -39,7 +39,6 @@ export function useAutoScroll({
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
userScrolledUpRef.current = false
|
||||
isFollowingRef.current = true
|
||||
}, [dependency])
|
||||
|
||||
@@ -49,19 +48,19 @@ export function useAutoScroll({
|
||||
const container = containerRef.current
|
||||
|
||||
const handleScroll = () => {
|
||||
if (isProgrammaticScrollRef.current) {
|
||||
isProgrammaticScrollRef.current = false
|
||||
return
|
||||
}
|
||||
|
||||
const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight
|
||||
const isScrolledUp = distanceFromBottom > SCROLL_THRESHOLD
|
||||
|
||||
if (isScrolledUp) {
|
||||
isFollowingRef.current = false
|
||||
} else {
|
||||
isFollowingRef.current = true
|
||||
}
|
||||
|
||||
if (userScrolledUpRef.current !== isScrolledUp) {
|
||||
userScrolledUpRef.current = isScrolledUp
|
||||
onScrollStateChange?.(isScrolledUp)
|
||||
}
|
||||
onScrollStateChange?.(isScrolledUp)
|
||||
}
|
||||
|
||||
container.addEventListener('scroll', handleScroll, { passive: true })
|
||||
|
||||
Reference in new issue
Block a user