Added focus restoration when closing commit changes search

This commit is contained in:
Abdelilah El Aissaoui 2024-09-11 10:44:23 +02:00
parent e38746cd0e
commit 0f5e4248b9
No known key found for this signature in database
GPG Key ID: 7587FC860F594869

View File

@ -33,6 +33,7 @@ import com.jetpackduba.gitnuro.ui.tree_files.TreeItem
import com.jetpackduba.gitnuro.viewmodels.CommitChangesStateUi
import com.jetpackduba.gitnuro.viewmodels.CommitChangesViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.eclipse.jgit.diff.DiffEntry
import org.eclipse.jgit.lib.PersonIdent
@ -47,10 +48,20 @@ fun CommitChanges(
onBlame: (String) -> Unit,
onHistory: (String) -> Unit,
) {
val tabFocusRequester = LocalTabFocusRequester.current
LaunchedEffect(selectedItem) {
commitChangesViewModel.loadChanges(selectedItem.revCommit)
}
LaunchedEffect(commitChangesViewModel) {
commitChangesViewModel.showSearch.collectLatest { show ->
if (!show) {
tabFocusRequester.requestFocus()
}
}
}
val commitChangesStatus = commitChangesViewModel.commitChangesStateUi.collectAsState().value
val showSearch by commitChangesViewModel.showSearch.collectAsState()
val changesListScroll by commitChangesViewModel.changesLazyListState.collectAsState()