From 19facc7c85a0e509b5d4ca1eaa98782f29477c9a Mon Sep 17 00:00:00 2001 From: Sherlock <1075773551@qq.com> Date: Thu, 14 Nov 2024 21:31:45 +0800 Subject: [PATCH 1/2] feat: support mort user-friendly scrolling --- app/components/chat.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 5669cc9a3..51fe74fe7 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -960,9 +960,24 @@ function _Chat() { (scrollRef.current.scrollTop + scrollRef.current.clientHeight), ) <= 1 : false; + const isAttachWithTop = useMemo(() => { + const lastMessage = scrollRef.current?.lastElementChild as HTMLElement; + // if scrolllRef is not ready or no message, return false + if (!scrollRef?.current || !lastMessage) return false; + const topDistance = + lastMessage!.getBoundingClientRect().top - + scrollRef.current.getBoundingClientRect().top; + // leave some space for user question + return topDistance < 100; + }, [scrollRef?.current?.scrollHeight]); + + const isTyping = userInput !== ""; + + // if user is typing, should auto scroll to bottom + // if user is not typing, should auto scroll to bottom only if already at bottom const { setAutoScroll, scrollDomToBottom } = useScrollToBottom( scrollRef, - isScrolledToBottom, + (isScrolledToBottom || isAttachWithTop) && !isTyping, ); const [hitBottom, setHitBottom] = useState(true); const isMobileScreen = useMobileScreen(); From e56216549efe58c1b734f5094eb77bfaa6654c69 Mon Sep 17 00:00:00 2001 From: opchips Date: Fri, 15 Nov 2024 11:56:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81=E5=9D=97=E5=B5=8C?= =?UTF-8?q?=E5=85=A5=E5=B0=8F=E4=BB=A3=E7=A0=81=E5=9D=97=E6=97=B6=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/markdown.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index f58b16427..ba85f0970 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -248,6 +248,10 @@ function escapeBrackets(text: string) { function tryWrapHtmlCode(text: string) { // try add wrap html code (fixed: html codeblock include 2 newline) + // ignore embed codeblock + if (text.includes("```")) { + return text; + } return text .replace( /([`]*?)(\w*?)([\n\r]*?)()/g,