| ... | @@ -67,16 +67,24 @@ export function estimateTimelineMessageHeight( | ... | @@ -67,16 +67,24 @@ export function estimateTimelineMessageHeight( |
| 67 | message: TimelineMessageHeightInput, | 67 | message: TimelineMessageHeightInput, |
| 68 | layout: TimelineHeightEstimateLayout = { timelineWidthPx: null }, | 68 | layout: TimelineHeightEstimateLayout = { timelineWidthPx: null }, |
| 69 | ): number { | 69 | ): number { |
| 70 | if (message.role !== "user") { | 70 | if (message.role === "assistant") { |
| 71 | const charsPerLine = estimateCharsPerLineForAssistant(layout.timelineWidthPx); | 71 | const charsPerLine = estimateCharsPerLineForAssistant(layout.timelineWidthPx); |
| 72 | const estimatedLines = estimateWrappedLineCount(message.text, charsPerLine); | 72 | const estimatedLines = estimateWrappedLineCount(message.text, charsPerLine); |
| 73 | return ASSISTANT_BASE_HEIGHT_PX + estimatedLines * LINE_HEIGHT_PX; | 73 | return ASSISTANT_BASE_HEIGHT_PX + estimatedLines * LINE_HEIGHT_PX; |
| 74 | } | 74 | } |
| 75 | | 75 | |
| 76 | const charsPerLine = estimateCharsPerLineForUser(layout.timelineWidthPx); | 76 | if (message.role === "user") { |
| | 77 | const charsPerLine = estimateCharsPerLineForUser(layout.timelineWidthPx); |
| | 78 | const estimatedLines = estimateWrappedLineCount(message.text, charsPerLine); |
| | 79 | const attachmentCount = message.attachments?.length ?? 0; |
| | 80 | const attachmentRows = Math.ceil(attachmentCount / ATTACHMENTS_PER_ROW); |
| | 81 | const attachmentHeight = attachmentRows * USER_ATTACHMENT_ROW_HEIGHT_PX; |
| | 82 | return USER_BASE_HEIGHT_PX + estimatedLines * LINE_HEIGHT_PX + attachmentHeight; |
| | 83 | } |
| | 84 | |
| | 85 | // `system` messages are not rendered in the chat timeline, but keep a stable |
| | 86 | // explicit branch in case they are present in timeline data. |
| | 87 | const charsPerLine = estimateCharsPerLineForAssistant(layout.timelineWidthPx); |
| 77 | const estimatedLines = estimateWrappedLineCount(message.text, charsPerLine); | 88 | const estimatedLines = estimateWrappedLineCount(message.text, charsPerLine); |
| 78 | const attachmentCount = message.attachments?.length ?? 0; | 89 | return ASSISTANT_BASE_HEIGHT_PX + estimatedLines * LINE_HEIGHT_PX; |
| 79 | const attachmentRows = Math.ceil(attachmentCount / ATTACHMENTS_PER_ROW); | | |
| 80 | const attachmentHeight = attachmentRows * USER_ATTACHMENT_ROW_HEIGHT_PX; | | |
| 81 | return USER_BASE_HEIGHT_PX + estimatedLines * LINE_HEIGHT_PX + attachmentHeight; | | |
| 82 | } | 90 | } |