Keep the channel tree's scroll position while the chat replaces it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:19:05 +00:00
co-authored by Claude Opus 5.5
parent f00490a663
commit 652027c1c1
2 changed files with 6 additions and 1 deletions
@@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowDown
@@ -100,9 +101,9 @@ fun ChannelTree(
/** The rows the find bar matched, and the one it is on, which a reveal does not flash. */ /** The rows the find bar matched, and the one it is on, which a reveal does not flash. */
found: Set<TreeRef> = emptySet(), found: Set<TreeRef> = emptySet(),
foundCurrent: TreeRef? = null, foundCurrent: TreeRef? = null,
listState: LazyListState = rememberLazyListState(),
) { ) {
val rows = remember(tree, collapsed, currentChannel) { flatten(tree, collapsed, currentChannel) } val rows = remember(tree, collapsed, currentChannel) { flatten(tree, collapsed, currentChannel) }
val listState = rememberLazyListState()
var flashing by remember { mutableStateOf<TreeRef?>(null) } var flashing by remember { mutableStateOf<TreeRef?>(null) }
LaunchedEffect(reveal, rows) { LaunchedEffect(reveal, rows) {
val ref = reveal ?: return@LaunchedEffect val ref = reveal ?: return@LaunchedEffect
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.ArrowDropDown
@@ -113,6 +114,8 @@ fun ServerScreen(
val collapsed by server.collapsed.collectAsStateWithLifecycle() val collapsed by server.collapsed.collectAsStateWithLifecycle()
var showChat by rememberSaveable { mutableStateOf(false) } var showChat by rememberSaveable { mutableStateOf(false) }
// Out here, so the tree keeps its place while the chat or another screen replaces it.
val treeList = rememberLazyListState()
var chatKey by rememberSaveable(stateSaver = ChatKeySaver) { mutableStateOf<ChatKey>(ChatKey.Channel) } var chatKey by rememberSaveable(stateSaver = ChatKeySaver) { mutableStateOf<ChatKey>(ChatKey.Channel) }
val conversation = chats[chatKey] ?: chats.channel val conversation = chats[chatKey] ?: chats.channel
var clientSheet by remember { mutableStateOf<Int?>(null) } var clientSheet by remember { mutableStateOf<Int?>(null) }
@@ -280,6 +283,7 @@ fun ServerScreen(
onRevealed = { reveal = null }, onRevealed = { reveal = null },
found = remember(treeHits) { treeHits.mapTo(HashSet()) { TreeRef(treeFind.channels, it) } }, found = remember(treeHits) { treeHits.mapTo(HashSet()) { TreeRef(treeFind.channels, it) } },
foundCurrent = treeAt?.takeIf { it in treeHits }?.let { TreeRef(treeFind.channels, it) }, foundCurrent = treeAt?.takeIf { it in treeHits }?.let { TreeRef(treeFind.channels, it) },
listState = treeList,
) )
} else { } else {
ChatPane( ChatPane(