From 2354602e6dfc5679d94eb32cd4ba0401d9b49301 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 31 Jan 2022 02:02:11 +0100 Subject: [PATCH] Selected branch is the first one always now --- src/main/kotlin/app/viewmodels/BranchesViewModel.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/viewmodels/BranchesViewModel.kt b/src/main/kotlin/app/viewmodels/BranchesViewModel.kt index c968377..d4abdc9 100644 --- a/src/main/kotlin/app/viewmodels/BranchesViewModel.kt +++ b/src/main/kotlin/app/viewmodels/BranchesViewModel.kt @@ -23,10 +23,19 @@ class BranchesViewModel @Inject constructor( get() = _currentBranch suspend fun loadBranches(git: Git) { + _currentBranch.value = branchesManager.currentBranchRef(git)?.name ?: "" + val branchesList = branchesManager.getBranches(git) + // set selected branch as the first one always + val selectedBranch = branchesList.find { it.name == _currentBranch.value } + if(selectedBranch != null) { + branchesList.remove(selectedBranch) + branchesList.add(0, selectedBranch) + } + + _branches.value = branchesList - _currentBranch.value = branchesManager.currentBranchRef(git)?.name ?: "" } fun createBranch(branchName: String) = tabState.safeProcessing { git ->