From 0f5e4248b987033f1c5f790beaaeac7dcf507aaf Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Wed, 11 Sep 2024 10:44:23 +0200 Subject: [PATCH] Added focus restoration when closing commit changes search --- .../com/jetpackduba/gitnuro/ui/CommitChanges.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt index c67cb46..af06c73 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt @@ -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()