From 886a438796eae00f67451cfd567e37b2159c5715 Mon Sep 17 00:00:00 2001 From: Neilzon Date: Thu, 19 Jan 2023 20:15:18 -0700 Subject: [PATCH 1/4] use theme background --- CodeEdit/Features/CodeFile/CodeFileView.swift | 18 ++++++++++++- .../StatusBarDrawer/StatusBarDrawer.swift | 25 ++++++++++++++++++- .../TerminalEmulatorView.swift | 6 +++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/CodeEdit/Features/CodeFile/CodeFileView.swift b/CodeEdit/Features/CodeFile/CodeFileView.swift index 6fc2990d2a..0c057f5e66 100644 --- a/CodeEdit/Features/CodeFile/CodeFileView.swift +++ b/CodeEdit/Features/CodeFile/CodeFileView.swift @@ -65,6 +65,7 @@ struct CodeFileView: View { $codeFile.content, language: getLanguage(), theme: $selectedTheme.editor.editorTheme, + useThemeBackground: $prefs.preferences.theme.useThemeBackground, font: $font, tabWidth: $prefs.preferences.textEditing.defaultTabWidth, lineHeight: $prefs.preferences.textEditing.lineHeightMultiple, @@ -72,7 +73,22 @@ struct CodeFileView: View { cursorPosition: codeFile.$cursorPosition ) .id(codeFile.fileURL) - .background(selectedTheme.editor.background.swiftColor) + .background { + if colorScheme == .dark { + if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedLightTheme { + Color.white + } else { + EffectView(.underPageBackground) + } + } else { + if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedDarkTheme { + Color.black + } else { + EffectView(.contentBackground) + } + + } + } .disabled(!editable) .frame(maxHeight: .infinity) .onChange(of: ThemeModel.shared.selectedTheme) { newValue in diff --git a/CodeEdit/Features/StatusBar/Views/StatusBarDrawer/StatusBarDrawer.swift b/CodeEdit/Features/StatusBar/Views/StatusBarDrawer/StatusBarDrawer.swift index 131a88a215..9280bcb1b1 100644 --- a/CodeEdit/Features/StatusBar/Views/StatusBarDrawer/StatusBarDrawer.swift +++ b/CodeEdit/Features/StatusBar/Views/StatusBarDrawer/StatusBarDrawer.swift @@ -11,6 +11,12 @@ struct StatusBarDrawer: View { @EnvironmentObject private var model: StatusBarViewModel + @ObservedObject + private var prefs: AppPreferencesModel = .shared + + @Environment(\.colorScheme) + private var colorScheme + @State private var searchText = "" @@ -27,7 +33,24 @@ struct StatusBarDrawer: View { var body: some View { VStack(spacing: 0) { switch model.selectedTab { - case 0: TerminalEmulatorView(url: model.workspaceURL) + case 0: + TerminalEmulatorView(url: model.workspaceURL) + .background { + if colorScheme == .dark { + if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedLightTheme { + Color.white + } else { + EffectView(.underPageBackground) + } + } else { + if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedDarkTheme { + Color.black + } else { + EffectView(.contentBackground) + } + + } + } default: Rectangle().foregroundColor(Color(nsColor: .textBackgroundColor)) } HStack(alignment: .center, spacing: 10) { diff --git a/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift b/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift index 9dc8b7b1c8..1c49e046c3 100644 --- a/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift +++ b/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift @@ -175,7 +175,8 @@ struct TerminalEmulatorView: NSViewRepresentable { terminal.caretColor = cursorColor terminal.selectedTextBackgroundColor = selectionColor terminal.nativeForegroundColor = textColor - terminal.nativeBackgroundColor = backgroundColor + terminal.nativeBackgroundColor = prefs.preferences.terminal.darkAppearance ? backgroundColor : .clear + terminal.layer?.backgroundColor = .clear terminal.optionAsMetaKey = optionAsMeta } terminal.appearance = colorAppearance @@ -201,7 +202,8 @@ struct TerminalEmulatorView: NSViewRepresentable { view.caretColor = cursorColor view.selectedTextBackgroundColor = selectionColor view.nativeForegroundColor = textColor - view.nativeBackgroundColor = backgroundColor + view.nativeBackgroundColor = prefs.preferences.terminal.darkAppearance ? backgroundColor : .clear + view.layer?.backgroundColor = .clear view.optionAsMetaKey = optionAsMeta view.appearance = colorAppearance if TerminalEmulatorView.lastTerminal[url.path] != nil { From 4dbe573b0f4d33dbcfbe97d87cfe30b644cb124c Mon Sep 17 00:00:00 2001 From: Neilzon Date: Fri, 20 Jan 2023 22:19:14 -0700 Subject: [PATCH 2/4] reorder CodeEditTextView arg list --- CodeEdit/Features/CodeFile/CodeFileView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CodeEdit/Features/CodeFile/CodeFileView.swift b/CodeEdit/Features/CodeFile/CodeFileView.swift index 0c057f5e66..fe19c8c8fc 100644 --- a/CodeEdit/Features/CodeFile/CodeFileView.swift +++ b/CodeEdit/Features/CodeFile/CodeFileView.swift @@ -65,12 +65,12 @@ struct CodeFileView: View { $codeFile.content, language: getLanguage(), theme: $selectedTheme.editor.editorTheme, - useThemeBackground: $prefs.preferences.theme.useThemeBackground, font: $font, tabWidth: $prefs.preferences.textEditing.defaultTabWidth, lineHeight: $prefs.preferences.textEditing.lineHeightMultiple, wrapLines: $prefs.preferences.textEditing.wrapLinesToEditorWidth, - cursorPosition: codeFile.$cursorPosition + cursorPosition: codeFile.$cursorPosition, + useThemeBackground: prefs.preferences.theme.useThemeBackground ) .id(codeFile.fileURL) .background { From f70e3a252d59652734622134fa6c5f1efd5d09af Mon Sep 17 00:00:00 2001 From: Neilzon Date: Sun, 22 Jan 2023 18:03:10 -0700 Subject: [PATCH 3/4] bump CodeEditTextView from 0.3.3 to 0.3.4 --- CodeEdit.xcodeproj/project.pbxproj | 2 +- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 4ad2c4204d..1b139db83c 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -3738,7 +3738,7 @@ repositoryURL = "https://github.com/CodeEditApp/CodeEditTextView.git"; requirement = { kind = exactVersion; - version = 0.3.3; + version = 0.3.4; }; }; 58F2EB18292FB91C004A9BDE /* XCRemoteSwiftPackageReference "Preferences" */ = { diff --git a/CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 63f87438c2..af7aed9b03 100644 --- a/CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/CodeEditApp/CodeEditTextView.git", "state" : { - "revision" : "9f79fa8a77ac8708951ef08ccfd4e9ba2e2ba7b2", - "version" : "0.3.3" + "revision" : "58f794154e9a392a9ac5aae93c39631b79ca7b9c", + "version" : "0.3.4" } }, { From 7cb48268ed603b760430a86b63bc0c483cfc7689 Mon Sep 17 00:00:00 2001 From: Neilzon Date: Sun, 22 Jan 2023 19:35:33 -0700 Subject: [PATCH 4/4] add use theme background terminal preference --- .../AppPreferences/Model/Terminal/TerminalPreferences.swift | 3 +++ .../Sections/ThemePreferences/TerminalThemeView.swift | 1 + CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift b/CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift index a4b78d9485..e125525a91 100644 --- a/CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift +++ b/CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift @@ -15,6 +15,9 @@ extension AppPreferences { /// If true terminal appearance will always be `dark`. Otherwise it adapts to the system setting. var darkAppearance: Bool = false + /// if true, the terminal uses the background color of the theme, otherwise it is clear + var useThemeBackground: Bool = true + /// If true, the terminal treats the `Option` key as the `Meta` key var optionAsMeta: Bool = false diff --git a/CodeEdit/Features/AppPreferences/Sections/ThemePreferences/TerminalThemeView.swift b/CodeEdit/Features/AppPreferences/Sections/ThemePreferences/TerminalThemeView.swift index 07a3e75b1d..6d481bb4f2 100644 --- a/CodeEdit/Features/AppPreferences/Sections/ThemePreferences/TerminalThemeView.swift +++ b/CodeEdit/Features/AppPreferences/Sections/ThemePreferences/TerminalThemeView.swift @@ -35,6 +35,7 @@ struct TerminalThemeView: View { private var topToggles: some View { VStack(alignment: .leading) { Toggle("Always use dark terminal appearance", isOn: $prefs.preferences.terminal.darkAppearance) + Toggle("Use theme background ", isOn: $prefs.preferences.terminal.useThemeBackground) } } diff --git a/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift b/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift index 1c49e046c3..391d37dab0 100644 --- a/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift +++ b/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift @@ -175,7 +175,7 @@ struct TerminalEmulatorView: NSViewRepresentable { terminal.caretColor = cursorColor terminal.selectedTextBackgroundColor = selectionColor terminal.nativeForegroundColor = textColor - terminal.nativeBackgroundColor = prefs.preferences.terminal.darkAppearance ? backgroundColor : .clear + terminal.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear terminal.layer?.backgroundColor = .clear terminal.optionAsMetaKey = optionAsMeta } @@ -202,7 +202,7 @@ struct TerminalEmulatorView: NSViewRepresentable { view.caretColor = cursorColor view.selectedTextBackgroundColor = selectionColor view.nativeForegroundColor = textColor - view.nativeBackgroundColor = prefs.preferences.terminal.darkAppearance ? backgroundColor : .clear + view.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear view.layer?.backgroundColor = .clear view.optionAsMetaKey = optionAsMeta view.appearance = colorAppearance