Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Show five lines for long user prompts (#1578)

Engel Nystaed9a485be36
diff --git a/__tests__/components/chat-message.test.tsx b/__tests__/components/chat-message.test.tsx
index 5980223ce0..89177d8ebe 100644
--- a/__tests__/components/chat-message.test.tsx
+++ b/__tests__/components/chat-message.test.tsx
@@ -56,9 +56,11 @@ describe("ChatMessage", () => {
globalThis.ResizeObserver =
FiringResizeObserver as unknown as typeof ResizeObserver;
- const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
- // No newlines and <= 220 chars, so truncation depends only on the measured
- // (mocked) height rather than the message length / newline heuristics.
+ const consoleError = vi
+ .spyOn(console, "error")
+ .mockImplementation(() => {});
+ // No newlines and below the length threshold, so truncation depends only
+ // on the measured height rather than length / newline heuristics.
const message = "word ".repeat(20).trim();
try {
@@ -158,19 +160,32 @@ describe("ChatMessage", () => {
expect(codeElement.closest("article")).not.toBeNull();
});
- it("truncates long sent user messages to three lines with view more on hover", async () => {
+ it("truncates long sent user messages to five lines with view more on hover", async () => {
const longMessage = `${"Here's a long message. ".repeat(40)}`.trim();
render(<ChatMessage type="user" message={longMessage} />);
- expect(screen.getByTestId("chat-message-truncation-gradient")).toBeInTheDocument();
- expect(screen.getByTestId("chat-message-view-more")).toHaveClass("opacity-0");
+ expect(
+ screen.getByText(longMessage).closest(".line-clamp-5"),
+ ).not.toBeNull();
+ expect(
+ screen.getByTestId("chat-message-truncation-gradient"),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId("chat-message-view-more")).toHaveClass(
+ "opacity-0",
+ );
fireEvent.mouseEnter(screen.getByTestId("user-message"));
- expect(screen.getByTestId("chat-message-view-more")).toHaveClass("opacity-100");
+ expect(screen.getByTestId("chat-message-view-more")).toHaveClass(
+ "opacity-100",
+ );
fireEvent.click(screen.getByTestId("chat-message-expand"));
- expect(screen.queryByTestId("chat-message-truncation-gradient")).not.toBeInTheDocument();
- expect(screen.queryByTestId("chat-message-view-more")).not.toBeInTheDocument();
+ expect(
+ screen.queryByTestId("chat-message-truncation-gradient"),
+ ).not.toBeInTheDocument();
+ expect(
+ screen.queryByTestId("chat-message-view-more"),
+ ).not.toBeInTheDocument();
});
it("shows a stop control for a sending user message and calls onStop when clicked", () => {
diff --git a/src/components/features/chat/user-message-body.tsx b/src/components/features/chat/user-message-body.tsx
index 1fb1bfa21e..4da4e98792 100644
--- a/src/components/features/chat/user-message-body.tsx
+++ b/src/components/features/chat/user-message-body.tsx
@@ -4,7 +4,8 @@ import { cn } from "#/utils/utils";
import { I18nKey } from "#/i18n/declaration";
import { MarkdownRenderer } from "../markdown/markdown-renderer";
-const USER_MESSAGE_MAX_LINES = 3;
+const USER_MESSAGE_MAX_LINES = 5;
+const USER_MESSAGE_LENGTH_THRESHOLD = 360;
export const USER_MESSAGE_LINE_HEIGHT_PX = 24;
export const chatBubbleMarkdownComponents = {
@@ -53,7 +54,7 @@ export function UserMessageBody({
const truncatable =
content.scrollHeight > maxHeight + 1 ||
newlineCount >= USER_MESSAGE_MAX_LINES ||
- message.trim().length > 220;
+ message.trim().length > USER_MESSAGE_LENGTH_THRESHOLD;
setIsTruncatable(truncatable);
};
@@ -74,7 +75,7 @@ export function UserMessageBody({
ref={contentRef}
className={cn(
"text-sm leading-6 whitespace-normal [word-break:break-word]",
- isCollapsed && "line-clamp-3",
+ isCollapsed && "line-clamp-5",
)}
>
<MarkdownRenderer