File tree Expand file tree Collapse file tree 1 file changed +18
-12
lines changed
tools/server/webui/src/lib/components/app/chat/ChatMessages Expand file tree Collapse file tree 1 file changed +18
-12
lines changed Original file line number Diff line number Diff line change 5353 textareaElement = $bindable ()
5454 }: Props = $props ();
5555
56- let innerWidth = $state (0 );
5756 let isMultiline = $state (false );
5857 let messageElement: HTMLElement | undefined = $state ();
5958
6059 $effect (() => {
61- if (messageElement && message .content .trim () && innerWidth > 0 ) {
62- if (message .content .includes (' \n ' )) {
63- isMultiline = true ;
64- return ;
60+ if (! messageElement || ! message .content .trim ()) return ;
61+
62+ if (message .content .includes (' \n ' )) {
63+ isMultiline = true ;
64+ return ;
65+ }
66+
67+ const resizeObserver = new ResizeObserver ((entries ) => {
68+ for (const entry of entries ) {
69+ const element = entry .target as HTMLElement ;
70+ const estimatedSingleLineHeight = 24 ; // Typical line height for text-md
71+
72+ isMultiline = element .offsetHeight > estimatedSingleLineHeight * 1.5 ;
6573 }
74+ });
6675
67- const computedStyle = window .getComputedStyle (messageElement );
68- const lineHeight = parseFloat (computedStyle .lineHeight );
69- const actualHeight = messageElement .scrollHeight ;
76+ resizeObserver .observe (messageElement );
7077
71- isMultiline = actualHeight > lineHeight * 1.2 ;
72- }
78+ return () => {
79+ resizeObserver .disconnect ();
80+ };
7381 });
7482 </script >
7583
76- <svelte:window bind:innerWidth />
77-
7884<div
7985 aria-label =" User message with actions"
8086 class ="group flex flex-col items-end gap-3 md:gap-2 {className }"
You can’t perform that action at this time.
0 commit comments