@@ -382,7 +382,22 @@ fun LogViewerScreen(
382 logEntry = logEntry,
382 logEntry = logEntry,
383 isExpanded = expandedLogKey == key,
383 isExpanded = expandedLogKey == key,
384 onClick = {
384 onClick = {
385− expandedLogKey = if (expandedLogKey == key) null else key
385+ if (expandedLogKey == key) {
386+ // Collapsing: if the top of the entry is scrolled
387+ // above the viewport, jump to it so the user sees
388+ // the collapsed card instead of a random position.
389+ val itemInfo = listState.layoutInfo.visibleItemsInfo
390+ .firstOrNull { it.index == index }
391+ val needsScroll = itemInfo == null || itemInfo.offset < 0
392+ expandedLogKey = null
395+ listState.animateScrollToItem(index)
399+ expandedLogKey = key
387 clipboardManager = clipboard,
402 clipboardManager = clipboard,
388 onCopied = {
403 onCopied = {