From 5667dc896275f8e22ac34e8e7e63c3d97cd89528 Mon Sep 17 00:00:00 2001 From: Kihron Date: Tue, 3 Dec 2024 13:05:46 -0500 Subject: [PATCH] - Fixed bug preventing switching to a different settings tab while inside the nested accounts page - Sidebar toggle is completely removed on versions above macOS 14+ - Known Issue: Sidebar toggling is not reliably hidden on versions macOS 13 and below due to the introduction of a NavigationStack --- .../AccountsSettingsView.swift | 57 ++++++++++--------- CodeEdit/Features/Settings/SettingsView.swift | 2 +- .../Views/View+HideSidebarToggle.swift | 22 ++++--- .../View+NavigationBarBackButtonVisible.swift | 5 +- 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsView.swift b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsView.swift index 92926889c..36b7c2d16 100644 --- a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsView.swift +++ b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsView.swift @@ -15,34 +15,39 @@ struct AccountsSettingsView: View { @State private var selectedProvider: SourceControlAccount.Provider? var body: some View { - SettingsForm { - Section { - if $gitAccounts.isEmpty { - Text("No accounts") - .foregroundColor(.secondary) - .frame(maxWidth: .infinity, alignment: .center) - } else { - ForEach($gitAccounts, id: \.self) { $account in - AccountsSettingsAccountLink($account) - } - } - } footer: { - HStack { - Spacer() - Button("Add Account...") { addAccountSheetPresented.toggle() } - .sheet(isPresented: $addAccountSheetPresented, content: { - AccountSelectionView(selectedProvider: $selectedProvider) - }) - .sheet(item: $selectedProvider, content: { provider in - switch provider { - case .github, .githubEnterprise, .gitlab, .gitlabSelfHosted: - AccountsSettingsSigninView(provider, addAccountSheetPresented: $addAccountSheetPresented) - default: - implementationNeeded + NavigationStack { + SettingsForm { + Section { + if $gitAccounts.isEmpty { + Text("No accounts") + .foregroundColor(.secondary) + .frame(maxWidth: .infinity, alignment: .center) + } else { + ForEach($gitAccounts, id: \.self) { $account in + AccountsSettingsAccountLink($account) } - }) + } + } footer: { + HStack { + Spacer() + Button("Add Account...") { addAccountSheetPresented.toggle() } + .sheet(isPresented: $addAccountSheetPresented, content: { + AccountSelectionView(selectedProvider: $selectedProvider) + }) + .sheet(item: $selectedProvider, content: { provider in + switch provider { + case .github, .githubEnterprise, .gitlab, .gitlabSelfHosted: + AccountsSettingsSigninView( + provider, + addAccountSheetPresented: $addAccountSheetPresented + ) + default: + implementationNeeded + } + }) + } + .padding(.top, 10) } - .padding(.top, 10) } } } diff --git a/CodeEdit/Features/Settings/SettingsView.swift b/CodeEdit/Features/Settings/SettingsView.swift index d7e7ef766..2f54adda0 100644 --- a/CodeEdit/Features/Settings/SettingsView.swift +++ b/CodeEdit/Features/Settings/SettingsView.swift @@ -156,6 +156,7 @@ struct SettingsView: View { } } .navigationSplitViewColumnWidth(215) + .hideSidebarToggle() } detail: { Group { switch selectedPage.name { @@ -184,7 +185,6 @@ struct SettingsView: View { } } .navigationSplitViewColumnWidth(500) - .hideSidebarToggle() .onAppear { model.backButtonVisible = false } diff --git a/CodeEdit/Features/Settings/Views/View+HideSidebarToggle.swift b/CodeEdit/Features/Settings/Views/View+HideSidebarToggle.swift index 09b65c858..cfebde90b 100644 --- a/CodeEdit/Features/Settings/Views/View+HideSidebarToggle.swift +++ b/CodeEdit/Features/Settings/Views/View+HideSidebarToggle.swift @@ -6,6 +6,7 @@ // import SwiftUI +import SwiftUIIntrospect extension View { func hideSidebarToggle() -> some View { @@ -15,14 +16,19 @@ extension View { struct HideSidebarToggleViewModifier: ViewModifier { func body(content: Content) -> some View { - content - .task { - let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }! - let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar" - let index = window.toolbar?.items.firstIndex { $0.itemIdentifier.rawValue == sidebaritem } - if let index { - window.toolbar?.removeItem(at: index) + if #available(macOS 14, *) { + content + .toolbar(removing: .sidebarToggle) + } else { + content + .task { + let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }! + let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar" + let index = window.toolbar?.items.firstIndex { $0.itemIdentifier.rawValue == sidebaritem } + if let index { + window.toolbar?.removeItem(at: index) + } } - } + } } } diff --git a/CodeEdit/Features/Settings/Views/View+NavigationBarBackButtonVisible.swift b/CodeEdit/Features/Settings/Views/View+NavigationBarBackButtonVisible.swift index f778e0e79..3acda3c01 100644 --- a/CodeEdit/Features/Settings/Views/View+NavigationBarBackButtonVisible.swift +++ b/CodeEdit/Features/Settings/Views/View+NavigationBarBackButtonVisible.swift @@ -24,10 +24,13 @@ struct NavigationBarBackButtonVisible: ViewModifier { } } } - .hideSidebarToggle() + .navigationBarBackButtonHidden() .onAppear { model.backButtonVisible = true } + .onDisappear { + model.backButtonVisible = false + } } }