From f20cfbb698342c8a1b2c99bb013395c6bbb80624 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Wed, 5 Jan 2022 01:51:08 +0100 Subject: [PATCH] Fixed tabs not selecting/creating the next tab properly --- src/main/kotlin/app/App.kt | 13 +++++++------ .../app/ui/components/RepositoriesTabPanel.kt | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/app/App.kt b/src/main/kotlin/app/App.kt index b86a7fb..e9bf2e2 100644 --- a/src/main/kotlin/app/App.kt +++ b/src/main/kotlin/app/App.kt @@ -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, 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) = 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 diff --git a/src/main/kotlin/app/ui/components/RepositoriesTabPanel.kt b/src/main/kotlin/app/ui/components/RepositoriesTabPanel.kt index ddd020a..91d4fa4 100644 --- a/src/main/kotlin/app/ui/components/RepositoriesTabPanel.kt +++ b/src/main/kotlin/app/ui/components/RepositoriesTabPanel.kt @@ -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