diff --git a/packages/ui/src/features/sessions/components/session-update/QueuedMessageView.tsx b/packages/ui/src/features/sessions/components/session-update/QueuedMessageView.tsx index 27508e6e4c..83b4152bbf 100644 --- a/packages/ui/src/features/sessions/components/session-update/QueuedMessageView.tsx +++ b/packages/ui/src/features/sessions/components/session-update/QueuedMessageView.tsx @@ -1,10 +1,12 @@ +import { useLayoutEffect, useRef, useState } from "react"; import { ArrowBendDownLeft, + CaretDown, PencilSimple, Stack, Trash, } from "@phosphor-icons/react"; -import { Button } from "@posthog/quill"; +import { Button, cn } from "@posthog/quill"; import { Box, Flex, IconButton, Tooltip } from "@radix-ui/themes"; import { MarkdownRenderer } from "../../../editor/components/MarkdownRenderer"; import type { QueuedMessage } from "../../sessionStore"; @@ -29,15 +31,57 @@ export function QueuedMessageView({ ? "Inject this message into the current turn at the next tool boundary." : "Interrupt the current turn and resend with this message."; + const [isExpanded, setIsExpanded] = useState(false); + const [isOverflowing, setIsOverflowing] = useState(false); + const textRef = useRef(null); + + // Only meaningful while collapsed: expanding removes the clamp so scrollHeight === clientHeight. + // We keep the prior result when expanded so the "Show less" trigger stays put. + // biome-ignore lint/correctness/useExhaustiveDependencies: re-measure when the message text changes. + useLayoutEffect(() => { + if (isExpanded) return; + const el = textRef.current; + if (!el) return; + const measure = () => + setIsOverflowing(el.scrollHeight - el.clientHeight > 1); + measure(); + const observer = new ResizeObserver(measure); + observer.observe(el); + return () => observer.disconnect(); + }, [message.content, isExpanded]); + return ( - - + + - {hasFileMentions(message.content) ? ( - parseFileMentions(message.content) - ) : ( - +
+ {hasFileMentions(message.content) ? ( + parseFileMentions(message.content) + ) : ( + + )} +
+ {isOverflowing && ( + )}