stabilize message auto scroll
This commit is contained in:
@@ -36,6 +36,7 @@ import { setActiveInstanceId } from "../stores/instances"
|
|||||||
|
|
||||||
const codeNomadLogo = new URL("../../images/CodeNomad-Icon.png", import.meta.url).href
|
const codeNomadLogo = new URL("../../images/CodeNomad-Icon.png", import.meta.url).href
|
||||||
const SCROLL_OFFSET = 64
|
const SCROLL_OFFSET = 64
|
||||||
|
const SCROLL_DIRECTION_THRESHOLD = 10
|
||||||
|
|
||||||
interface TaskSessionLocation {
|
interface TaskSessionLocation {
|
||||||
sessionId: string
|
sessionId: string
|
||||||
@@ -265,13 +266,13 @@ export default function MessageStream(props: MessageStreamProps) {
|
|||||||
if (!containerRef) return
|
if (!containerRef) return
|
||||||
|
|
||||||
const currentScrollTop = containerRef.scrollTop
|
const currentScrollTop = containerRef.scrollTop
|
||||||
const movingUp = currentScrollTop < lastKnownScrollTop - 1
|
const movingUp = currentScrollTop < lastKnownScrollTop - SCROLL_DIRECTION_THRESHOLD
|
||||||
lastKnownScrollTop = currentScrollTop
|
lastKnownScrollTop = currentScrollTop
|
||||||
|
|
||||||
const atBottom = isNearBottom(containerRef)
|
const atBottom = isNearBottom(containerRef)
|
||||||
|
|
||||||
if (isUserScroll) {
|
if (isUserScroll) {
|
||||||
if ((movingUp || !atBottom) && autoScroll()) {
|
if (movingUp && !atBottom && autoScroll()) {
|
||||||
setAutoScroll(false)
|
setAutoScroll(false)
|
||||||
} else if (!movingUp && atBottom && !autoScroll()) {
|
} else if (!movingUp && atBottom && !autoScroll()) {
|
||||||
setAutoScroll(true)
|
setAutoScroll(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user