diff --git a/App/Tabs/TabBarView.swift b/App/Tabs/TabBarView.swift index c08b526..1b59846 100644 --- a/App/Tabs/TabBarView.swift +++ b/App/Tabs/TabBarView.swift @@ -156,7 +156,11 @@ class TabBarView: UIView } else { let newTabView = makeTabView(withIdentifier: identifier) if animated { newTabView.collapsed = true } - tabViews.append(newTabView) + if i < tabViews.count { + tabViews.insert(newTabView, at: i - 1) + } else { + tabViews.append(newTabView) + } } } diff --git a/App/Tabs/TabController.swift b/App/Tabs/TabController.swift index 0017c9c..f3a5c3d 100644 --- a/App/Tabs/TabController.swift +++ b/App/Tabs/TabController.swift @@ -33,7 +33,11 @@ class TabController func createNewTab(url: URL?, webViewConfiguration: WKWebViewConfiguration?) -> Tab { let tab = Tab(url: url, policyManager: policyManager, webViewConfiguration: webViewConfiguration) - tabs.append(tab) + if tabs.count > 0 { + tabs.insert(tab, at: activeTabIndex + 1) + } else { + tabs.append(tab) + } return tab } @@ -43,7 +47,9 @@ class TabController tabs.remove(at: index) if tabs.count > 0 { - if index < tabs.count { + if (index - 1) >= 0 { + activeTabIndex = index - 1 + } else if index < tabs.count { activeTabIndex = index } else { activeTabIndex = tabs.count - 1