@@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.height
1919import androidx.compose.foundation.layout.padding
2020import androidx.compose.foundation.layout.size
2121import androidx.compose.foundation.layout.width
22+ import androidx.compose.foundation.lazy.rememberLazyListState
2223import androidx.compose.foundation.shape.CircleShape
2324import androidx.compose.foundation.shape.RoundedCornerShape
2425import androidx.compose.material.CircularProgressIndicator
@@ -122,6 +123,7 @@ private fun Content(
122123) {
123124 val coroutineScope = rememberCoroutineScope()
124125 val searchState = rememberSearchState()
126+ val listState = rememberLazyListState()
125127 val searchQuery by remember(searchState.query) { mutableStateOf(searchState.query.orEmpty()) }
126128 var showSidebar by remember { mutableStateOf(false ) }
127129
@@ -133,6 +135,13 @@ private fun Content(
133135 }
134136 }
135137
138+ val resultIndex = searchState.selectedResultListIndex
139+ LaunchedEffect (resultIndex) {
140+ if (resultIndex != null && ! listState.isScrollInProgress) {
141+ listState.animateScrollToItem(resultIndex)
142+ }
143+ }
144+
136145 Column (
137146 modifier = Modifier
138147 .fillMaxSize()
@@ -174,7 +183,7 @@ private fun Content(
174183 Spacer (modifier = Modifier .width(8 .dp))
175184
176185 Text (
177- text = " ${searchState.selectedResult } /${searchState.totalResults} " ,
186+ text = " ${searchState.selectedResultListIndex?. let { it + 1 } ? : 0 } /${searchState.totalResults} " ,
178187 color = Color .Gray
179188 )
180189
@@ -194,6 +203,7 @@ private fun Content(
194203 modifier = Modifier .weight(1F ),
195204 json = json,
196205 searchState = searchState,
206+ lazyListState = listState,
197207 showIndices = true ,
198208 showItemCount = true ,
199209 expandSingleChildren = true ,
0 commit comments