Skip to content

Commit 8a547c5

Browse files
authored
use theme background (#1004)
* use theme background * reorder CodeEditTextView arg list * bump CodeEditTextView from 0.3.3 to 0.3.4 * add use theme background terminal preference
1 parent 0fcdda7 commit 8a547c5

7 files changed

Lines changed: 53 additions & 8 deletions

File tree

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3806,7 +3806,7 @@
38063806
repositoryURL = "https://github.com/CodeEditApp/CodeEditTextView.git";
38073807
requirement = {
38083808
kind = exactVersion;
3809-
version = 0.3.3;
3809+
version = 0.3.4;
38103810
};
38113811
};
38123812
58F2EB18292FB91C004A9BDE /* XCRemoteSwiftPackageReference "Preferences" */ = {

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeEdit/Features/AppPreferences/Model/Terminal/TerminalPreferences.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ extension AppPreferences {
1515
/// If true terminal appearance will always be `dark`. Otherwise it adapts to the system setting.
1616
var darkAppearance: Bool = false
1717

18+
/// if true, the terminal uses the background color of the theme, otherwise it is clear
19+
var useThemeBackground: Bool = true
20+
1821
/// If true, the terminal treats the `Option` key as the `Meta` key
1922
var optionAsMeta: Bool = false
2023

CodeEdit/Features/AppPreferences/Sections/ThemePreferences/TerminalThemeView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct TerminalThemeView: View {
3535
private var topToggles: some View {
3636
VStack(alignment: .leading) {
3737
Toggle("Always use dark terminal appearance", isOn: $prefs.preferences.terminal.darkAppearance)
38+
Toggle("Use theme background ", isOn: $prefs.preferences.terminal.useThemeBackground)
3839
}
3940
}
4041

CodeEdit/Features/CodeFile/CodeFileView.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,26 @@ struct CodeFileView: View {
6969
tabWidth: $prefs.preferences.textEditing.defaultTabWidth,
7070
lineHeight: $prefs.preferences.textEditing.lineHeightMultiple,
7171
wrapLines: $prefs.preferences.textEditing.wrapLinesToEditorWidth,
72-
cursorPosition: codeFile.$cursorPosition
72+
cursorPosition: codeFile.$cursorPosition,
73+
useThemeBackground: prefs.preferences.theme.useThemeBackground
7374
)
7475
.id(codeFile.fileURL)
75-
.background(selectedTheme.editor.background.swiftColor)
76+
.background {
77+
if colorScheme == .dark {
78+
if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedLightTheme {
79+
Color.white
80+
} else {
81+
EffectView(.underPageBackground)
82+
}
83+
} else {
84+
if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedDarkTheme {
85+
Color.black
86+
} else {
87+
EffectView(.contentBackground)
88+
}
89+
90+
}
91+
}
7692
.disabled(!editable)
7793
.frame(maxHeight: .infinity)
7894
.onChange(of: ThemeModel.shared.selectedTheme) { newValue in

CodeEdit/Features/StatusBar/Views/StatusBarDrawer/StatusBarDrawer.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ struct StatusBarDrawer: View {
1111
@EnvironmentObject
1212
private var model: StatusBarViewModel
1313

14+
@ObservedObject
15+
private var prefs: AppPreferencesModel = .shared
16+
17+
@Environment(\.colorScheme)
18+
private var colorScheme
19+
1420
@State
1521
private var searchText = ""
1622

@@ -27,7 +33,24 @@ struct StatusBarDrawer: View {
2733
var body: some View {
2834
VStack(spacing: 0) {
2935
switch model.selectedTab {
30-
case 0: TerminalEmulatorView(url: model.workspaceURL)
36+
case 0:
37+
TerminalEmulatorView(url: model.workspaceURL)
38+
.background {
39+
if colorScheme == .dark {
40+
if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedLightTheme {
41+
Color.white
42+
} else {
43+
EffectView(.underPageBackground)
44+
}
45+
} else {
46+
if prefs.preferences.theme.selectedTheme == prefs.preferences.theme.selectedDarkTheme {
47+
Color.black
48+
} else {
49+
EffectView(.contentBackground)
50+
}
51+
52+
}
53+
}
3154
default: Rectangle().foregroundColor(Color(nsColor: .textBackgroundColor))
3255
}
3356
HStack(alignment: .center, spacing: 10) {

CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ struct TerminalEmulatorView: NSViewRepresentable {
175175
terminal.caretColor = cursorColor
176176
terminal.selectedTextBackgroundColor = selectionColor
177177
terminal.nativeForegroundColor = textColor
178-
terminal.nativeBackgroundColor = backgroundColor
178+
terminal.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
179+
terminal.layer?.backgroundColor = .clear
179180
terminal.optionAsMetaKey = optionAsMeta
180181
}
181182
terminal.appearance = colorAppearance
@@ -201,7 +202,8 @@ struct TerminalEmulatorView: NSViewRepresentable {
201202
view.caretColor = cursorColor
202203
view.selectedTextBackgroundColor = selectionColor
203204
view.nativeForegroundColor = textColor
204-
view.nativeBackgroundColor = backgroundColor
205+
view.nativeBackgroundColor = prefs.preferences.terminal.useThemeBackground ? backgroundColor : .clear
206+
view.layer?.backgroundColor = .clear
205207
view.optionAsMetaKey = optionAsMeta
206208
view.appearance = colorAppearance
207209
if TerminalEmulatorView.lastTerminal[url.path] != nil {

0 commit comments

Comments
 (0)