Skip to content

Commit a4c30b6

Browse files
committed
fix(ui): auto-scroll to expanded agent message items
Ensure the message list scrolls to the bottom when a tool or command result is expanded, improving visibility of expanded content in the agent timeline.
1 parent ef84ab9 commit a4c30b6

File tree

3 files changed

+184
-133
lines changed

3 files changed

+184
-133
lines changed

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/agent/AgentMessageList.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,18 @@ fun AgentMessageList(
6666
verticalArrangement = Arrangement.spacedBy(6.dp) // Reduce spacing
6767
) {
6868
items(renderer.timeline) { timelineItem ->
69-
RenderMessageItem(timelineItem, onOpenFileViewer, renderer)
69+
RenderMessageItem(
70+
timelineItem = timelineItem,
71+
onOpenFileViewer = onOpenFileViewer,
72+
renderer = renderer,
73+
onExpand = {
74+
coroutineScope.launch {
75+
// Scroll to the bottom when an item expands, to ensure visibility
76+
// This fixes the issue where expanding an item (like a tool result) doesn't trigger auto-scroll
77+
listState.animateScrollToItem(maxOf(0, listState.layoutInfo.totalItemsCount - 1))
78+
}
79+
}
80+
)
7081
}
7182

7283
if (renderer.currentStreamingOutput.isNotEmpty()) {
@@ -87,7 +98,8 @@ fun AgentMessageList(
8798
fun RenderMessageItem(
8899
timelineItem: ComposeRenderer.TimelineItem,
89100
onOpenFileViewer: ((String) -> Unit)?,
90-
renderer: ComposeRenderer
101+
renderer: ComposeRenderer,
102+
onExpand: () -> Unit = {}
91103
) {
92104
when (timelineItem) {
93105
is ComposeRenderer.TimelineItem.MessageItem -> {
@@ -110,7 +122,8 @@ fun RenderMessageItem(
110122
fullOutput = timelineItem.fullOutput,
111123
executionTimeMs = timelineItem.executionTimeMs,
112124
docqlStats = timelineItem.docqlStats,
113-
onOpenFileViewer = onOpenFileViewer
125+
onOpenFileViewer = onOpenFileViewer,
126+
onExpand = onExpand
114127
)
115128
}
116129

@@ -140,7 +153,8 @@ fun RenderMessageItem(
140153
command = timelineItem.command,
141154
output = timelineItem.output,
142155
exitCode = timelineItem.exitCode,
143-
executionTimeMs = timelineItem.executionTimeMs
156+
executionTimeMs = timelineItem.executionTimeMs,
157+
onExpand = onExpand
144158
)
145159
}
146160

0 commit comments

Comments
 (0)