@@ -40,11 +40,12 @@ class TabsManager @Inject constructor(
4040
4141 _tabsFlow .value = repositoriesList.ifEmpty { listOf (newAppTab()) }
4242
43- val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected
43+ val latestSelectedTabIndex = appSettingsRepository.latestRepositoryTabSelected
4444
45- val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }
46-
47- _currentTab .value = latestSelectedTab ? : _tabsFlow .value.first()
45+ _currentTab .value = when (latestSelectedTabIndex < 0 ) {
46+ true -> _tabsFlow .value.first()
47+ false -> tabsFlow.value[latestSelectedTabIndex]
48+ }
4849 }
4950
5051 fun addNewTabFromPath (path : String , selectTab : Boolean , tabToBeReplacedPath : String? = null) {
@@ -79,7 +80,7 @@ class TabsManager @Inject constructor(
7980 }
8081
8182 private fun persistTabSelected (tab : TabInformation ) {
82- appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty( )
83+ appSettingsRepository.latestRepositoryTabSelected = tabsFlow.value.indexOf(tab )
8384 }
8485
8586 fun closeTab (tab : TabInformation ) {
@@ -116,10 +117,10 @@ class TabsManager @Inject constructor(
116117 }
117118
118119 private fun updatePersistedTabs () {
119- val tabsPaths = tabsFlow.value
120- .mapNotNull { it.path }
120+ val tabs = tabsFlow.value.filter { it.path != null }
121121
122- appSettingsRepository.latestTabsOpened = Json .encodeToString(tabsPaths)
122+ appSettingsRepository.latestTabsOpened = Json .encodeToString(tabs.map { it.path })
123+ appSettingsRepository.latestRepositoryTabSelected = tabs.indexOf(currentTab.value)
123124 }
124125
125126 fun addNewEmptyTab () {
0 commit comments