-
Notifications
You must be signed in to change notification settings - Fork 88
[LUM-833] Fix long user messages getting cut off in chat view #25579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
17bf7de
b2286e3
2a0283d
03db714
28109eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,9 @@ struct ChatBubble: View, Equatable { | |
| var isLatestAssistantMessage: Bool = false | ||
| var typographyGeneration: Int = 0 | ||
| @State private var isUserMessageExpanded: Bool = false | ||
| @State private var userMessageIntrinsicHeight: CGFloat = 0 | ||
| private let userMessageMaxCollapsedHeight: CGFloat = 150 | ||
| private static let heuristicUserCollapseCharacterThreshold = 3_000 | ||
| private static let heuristicUserCollapseLineThreshold = 40 | ||
|
|
||
| static let heuristicUserCollapseCharacterThreshold = 3_000 | ||
| static let heuristicUserCollapseLineThreshold = 40 | ||
| private static let heuristicUserPreviewCharacterLimit = 1_200 | ||
| private static let heuristicUserPreviewLineLimit = 24 | ||
|
|
||
|
|
@@ -558,7 +557,7 @@ struct ChatBubble: View, Equatable { | |
| Self.collapsedPreviewText(from: message.text) | ||
| } | ||
|
|
||
| private static func exceedsLineLimit(_ text: String, limit: Int) -> Bool { | ||
| static func exceedsLineLimit(_ text: String, limit: Int) -> Bool { | ||
| guard limit > 0 else { return !text.isEmpty } | ||
| var lineCount = 1 | ||
| for character in text { | ||
|
|
@@ -571,7 +570,7 @@ struct ChatBubble: View, Equatable { | |
| return false | ||
| } | ||
|
|
||
| private static func collapsedPreviewText(from text: String) -> String { | ||
| static func collapsedPreviewText(from text: String) -> String { | ||
| let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !trimmedText.isEmpty else { return text } | ||
|
|
||
|
|
@@ -591,101 +590,10 @@ struct ChatBubble: View, Equatable { | |
| return preview == trimmedText ? preview : "\(preview)\n\n..." | ||
| } | ||
|
|
||
| /// Estimates whether the user message text will exceed the collapse | ||
| /// threshold when rendered. Used on the first frame before | ||
| /// `onGeometryChange` has fired to avoid a full-height flash. | ||
| private var estimatedTextExceedsCollapseThreshold: Bool { | ||
| guard isUser, !message.isStreaming else { return false } | ||
| let text = message.text as NSString | ||
| let contentWidth = max(bubbleMaxWidth - 2 * VSpacing.lg, 0) | ||
| let font = NSFont.systemFont(ofSize: 14, weight: .regular) | ||
| let textRect = text.boundingRect( | ||
| with: NSSize(width: contentWidth, height: .greatestFiniteMagnitude), | ||
| options: [.usesLineFragmentOrigin, .usesFontLeading], | ||
| attributes: [.font: font] | ||
| ) | ||
| return ceil(textRect.height) > userMessageMaxCollapsedHeight | ||
| } | ||
|
|
||
| // MARK: - User Message Collapse / Expand | ||
| // | ||
| // .frame(maxHeight:) creates _FlexFrameLayout which recursively measures | ||
| // children and resolves explicitAlignment through the entire LazyVStack | ||
| // subtree — O(n × depth) per layout pass, causing 35 s+ hangs. | ||
| // | ||
| // Fix: .frame(height:) creates _FrameLayout — O(1), no alignment cascade. | ||
| // When height is nil (expanded / short), _FrameLayout passes through the | ||
| // child's natural height. Single view identity is preserved (no | ||
| // _ConditionalContent), so withAnimation still drives a smooth height | ||
| // transition on expand/collapse. | ||
|
|
||
| @ViewBuilder | ||
| private func userMessageHeightWrapper<Content: View>(@ViewBuilder _ content: () -> Content) -> some View { | ||
| let isCollapsible = userMessageIntrinsicHeight > 0 | ||
| ? userMessageIntrinsicHeight > userMessageMaxCollapsedHeight | ||
| : estimatedTextExceedsCollapseThreshold | ||
| let needsCollapse = isCollapsible && !isUserMessageExpanded | ||
| VStack(alignment: .leading, spacing: 0) { | ||
| content() | ||
| .onGeometryChange(for: CGFloat.self) { proxy in | ||
| proxy.size.height | ||
| } action: { height in | ||
| userMessageIntrinsicHeight = height | ||
| } | ||
| .frame(height: needsCollapse ? userMessageMaxCollapsedHeight : nil, alignment: .top) | ||
| .clipped() | ||
| .overlay(alignment: .bottom) { | ||
| if needsCollapse { | ||
| LinearGradient( | ||
| colors: [ | ||
| VColor.surfaceLift.opacity(0), | ||
| VColor.surfaceLift | ||
| ], | ||
| startPoint: .init(x: 0.5, y: 0), | ||
| endPoint: .init(x: 0.5, y: 1) | ||
| ) | ||
| .frame(height: 40) | ||
| .allowsHitTesting(false) | ||
| } | ||
| } | ||
|
|
||
| if isCollapsible { | ||
| collapseToggleButton | ||
| .padding(.horizontal, VSpacing.lg) | ||
| .padding(.bottom, VSpacing.sm) | ||
| } | ||
| } | ||
| .if(isCollapsible) { view in | ||
| view | ||
| .background( | ||
| RoundedRectangle(cornerRadius: VRadius.lg) | ||
| .fill(VColor.surfaceLift) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func heuristicUserMessageCollapseWrapper<Content: View>(@ViewBuilder _ content: () -> Content) -> some View { | ||
| VStack(alignment: .leading, spacing: 0) { | ||
| content() | ||
| // Clip to same height as the measurement-based collapse path | ||
| // so both produce a consistent collapsed height. | ||
| .frame(height: isUserMessageExpanded ? nil : userMessageMaxCollapsedHeight, alignment: .top) | ||
| .clipped() | ||
| .overlay(alignment: .bottom) { | ||
| if !isUserMessageExpanded { | ||
| LinearGradient( | ||
| colors: [ | ||
| VColor.surfaceLift.opacity(0), | ||
| VColor.surfaceLift | ||
| ], | ||
| startPoint: .init(x: 0.5, y: 0), | ||
| endPoint: .init(x: 0.5, y: 1) | ||
| ) | ||
| .frame(height: 40) | ||
| .allowsHitTesting(false) | ||
| } | ||
| } | ||
| collapseToggleButton | ||
| .padding(.horizontal, VSpacing.lg) | ||
| .padding(.bottom, VSpacing.sm) | ||
|
Comment on lines
593
to
599
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Heuristic collapse wrapper no longer clips content height — relies entirely on text truncation The old (Refers to lines 593-605) Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct — the heuristic collapse wrapper now relies entirely on text truncation (1,200 chars / 24 lines) rather than height clipping. This is intentional: the text truncation provides a proper expand flow with "Show more" button, while the old height clipping just cut content off visually. The attachment visibility change is also intentional — attachments should be visible even when the text portion is collapsed, since they're the primary content the user shared. |
||
|
|
@@ -848,7 +756,7 @@ struct ChatBubble: View, Equatable { | |
| if shouldUseHeuristicCollapse { | ||
| heuristicUserMessageCollapseWrapper { chrome } | ||
| } else { | ||
| userMessageHeightWrapper { chrome } | ||
| chrome | ||
|
Comment on lines
756
to
+759
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Switching non-heuristic user messages to render Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b2286e3. Removed the stale 260pt early return for attachment messages and added a per-attachment height estimate (~200pt each) to the minHeight calculation for both heuristic-collapsed and non-collapsed paths. |
||
| } | ||
| } else { | ||
| chrome | ||
|
|
||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.