Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Theme not updating on click #1255

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct CodeFileView: View {
@Environment(\.colorScheme)
private var colorScheme

@StateObject
private var themeModel: ThemeModel = .shared

private var cancellables = [AnyCancellable]()

private let isEditable: Bool
Expand Down Expand Up @@ -99,15 +102,15 @@ struct CodeFileView: View {
)
// minHeight zero fixes a bug where the app would freeze if the contents of the file are empty.
.frame(minHeight: .zero, maxHeight: .infinity)
.onChange(of: ThemeModel.shared.selectedTheme) { newValue in
.onChange(of: themeModel.selectedTheme) { newValue in
guard let theme = newValue else { return }
self.selectedTheme = theme
}
.onChange(of: colorScheme) { newValue in
if matchAppearance {
ThemeModel.shared.selectedTheme = newValue == .dark
? ThemeModel.shared.selectedDarkTheme!
: ThemeModel.shared.selectedLightTheme!
themeModel.selectedTheme = newValue == .dark
? themeModel.selectedDarkTheme
: themeModel.selectedLightTheme
}
}
.onChange(of: settingsFont) { _ in
Expand Down