From 949617a1dd7cdb6fd2236dc481a9b11d8cc8e8af Mon Sep 17 00:00:00 2001 From: Ryan Hopper-Lowe Date: Thu, 6 Mar 2025 09:20:11 -0600 Subject: [PATCH] fix: reset to instant-scroll when Signed-off-by: Ryan Hopper-Lowe --- ui/user/src/lib/components/Thread.svelte | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ui/user/src/lib/components/Thread.svelte b/ui/user/src/lib/components/Thread.svelte index cd9bd5537..ca6b597fc 100644 --- a/ui/user/src/lib/components/Thread.svelte +++ b/ui/user/src/lib/components/Thread.svelte @@ -2,13 +2,14 @@ import { sticktobottom, type StickToBottomControls } from '$lib/actions/div.svelte'; import Input from '$lib/components/messages/Input.svelte'; import Message from '$lib/components/messages/Message.svelte'; - import { Thread } from '$lib/services/chat/thread.svelte'; - import { ChatService, EditorService, type Messages, type Project } from '$lib/services'; - import { fade } from 'svelte/transition'; - import { onDestroy } from 'svelte'; + import { getLayout } from '$lib/context/layout.svelte'; import { toHTMLFromMarkdown } from '$lib/markdown'; + import { ChatService, EditorService, type Messages, type Project } from '$lib/services'; + import { Thread } from '$lib/services/chat/thread.svelte'; import type { EditorItem } from '$lib/services/editor/index.svelte'; - import { getLayout } from '$lib/context/layout.svelte'; + import { onDestroy } from 'svelte'; + import type { UIEventHandler } from 'svelte/elements'; + import { fade } from 'svelte/transition'; interface Props { id?: string; @@ -24,15 +25,6 @@ let messagesDiv = $state(); let scrollSmooth = $state(false); - $effect(() => { - const update = () => (scrollSmooth = true); - container?.addEventListener('scroll', update); - return () => { - container?.removeEventListener('scroll', update); - scrollSmooth = false; - }; - }); - $effect(() => { // Close and recreate thread if id changes if (thread && thread.threadID !== id) { @@ -44,6 +36,8 @@ }; } + scrollSmooth = false; + if (id && !thread) { constructThread(); } @@ -89,6 +83,15 @@ thread = newThread; } + const onScrollEnd: UIEventHandler = (e) => { + const isAtBottom = + e.currentTarget.scrollHeight - e.currentTarget.scrollTop - e.currentTarget.clientHeight <= 0; + + if (isAtBottom) { + scrollSmooth = true; + } + }; + function onSendCredentials(id: string, credentials: Record) { thread?.sendCredentials(id, credentials); } @@ -103,6 +106,7 @@ contentEl: messagesDiv, setControls: (controls) => (scrollControls = controls) }} + onscrollend={onScrollEnd} >