Fixed tabs not selecting/creating the next tab properly

This commit is contained in:
Abdelilah El Aissaoui 2022-01-05 01:51:08 +01:00
parent 9271dcdd60
commit f20cfbb698
2 changed files with 8 additions and 7 deletions

View File

@ -137,10 +137,10 @@ class App {
selectedTabKey = selectedTabKey,
onOpenSettings = onOpenSettings,
onAddedTab = { tabInfo ->
addTab(tabs, tabInfo)
addTab(tabInfo)
},
onRemoveTab = { key ->
removeTab(tabs, key)
removeTab(key)
}
)
@ -148,8 +148,9 @@ class App {
}
}
private fun removeTab(tabs: List<TabInformation>, key: Int) = appScope.launch(Dispatchers.IO) {
private fun removeTab(key: Int) = appScope.launch(Dispatchers.IO) {
// Stop any running jobs
val tabs = tabsFlow.value
val tabToRemove = tabs.firstOrNull { it.key == key } ?: return@launch
tabToRemove.tabViewModel.dispose()
@ -157,11 +158,11 @@ class App {
appStateManager.repositoryTabRemoved(key)
// Remove from tabs flow
tabsFlow.value = tabs.filter { tab -> tab.key != key }
tabsFlow.value = tabsFlow.value.filter { tab -> tab.key != key }
}
fun addTab(tabsList: List<TabInformation>, tabInformation: TabInformation) = appScope.launch(Dispatchers.IO) {
tabsFlow.value = tabsList.toMutableList().apply { add(tabInformation) }
fun addTab(tabInformation: TabInformation) = appScope.launch(Dispatchers.IO) {
tabsFlow.value = tabsFlow.value.toMutableList().apply { add(tabInformation) }
}
@Composable

View File

@ -69,7 +69,7 @@ fun RepositoriesTabPanel(
} else if (index == tabs.count() -1 && tabs.count() >= 2)
index - 1 // If the last tab is selected, select the previous one
else if (tabs.count() >= 2)
index // If any in between tab is selected, select the next one
index + 1 // If any in between tab is selected, select the next one
else
-1 // If there aren't any additional tabs once we remove this one