mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Stop auto-follow on any user scroll event
This commit is contained in:
1 parent
2d7de3496f
commit
d534ef1c6c
1 file changed
+9
-5
@@ -30,9 +30,11 @@ export function useAutoScroll<T extends Message>({
|
||||
const isFollowingRef = useRef(true)
|
||||
const lastMessageCountRef = useRef(0)
|
||||
const hasInitialScrolledRef = useRef(false)
|
||||
const isProgrammaticScrollRef = useRef(false)
|
||||
|
||||
const scrollToBottom = useCallback(() => {
|
||||
if (!containerRef?.current) return
|
||||
isProgrammaticScrollRef.current = true
|
||||
containerRef.current.scrollTop = containerRef.current.scrollHeight
|
||||
isFollowingRef.current = true
|
||||
onScrollStateChange?.(false)
|
||||
@@ -50,13 +52,15 @@ export function useAutoScroll<T extends Message>({
|
||||
const container = containerRef.current
|
||||
|
||||
const handleScroll = () => {
|
||||
const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight
|
||||
const isScrolledUp = distanceFromBottom > SCROLL_THRESHOLD
|
||||
|
||||
if (isScrolledUp) {
|
||||
isFollowingRef.current = false
|
||||
if (isProgrammaticScrollRef.current) {
|
||||
isProgrammaticScrollRef.current = false
|
||||
return
|
||||
}
|
||||
|
||||
isFollowingRef.current = false
|
||||
|
||||
const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight
|
||||
const isScrolledUp = distanceFromBottom > SCROLL_THRESHOLD
|
||||
onScrollStateChange?.(isScrolledUp)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user