@@ -46,7 +46,7 @@ struct CodeFileView: View {
46
46
47
47
@EnvironmentObject private var editorManager : EditorManager
48
48
49
- @StateObject private var themeModel : ThemeModel = . shared
49
+ @ObservedObject private var themeModel : ThemeModel = . shared
50
50
51
51
private var cancellables = Set < AnyCancellable > ( )
52
52
@@ -77,7 +77,9 @@ struct CodeFileView: View {
77
77
codeFile. undoManager = self . undoManager. manager
78
78
}
79
79
80
- @State private var selectedTheme = ThemeModel . shared. selectedTheme ?? ThemeModel . shared. themes. first!
80
+ private var currentTheme : Theme {
81
+ themeModel. selectedTheme ?? themeModel. themes. first!
82
+ }
81
83
82
84
@State private var font : NSFont = Settings [ \. textEditing] . font. current
83
85
@@ -107,7 +109,7 @@ struct CodeFileView: View {
107
109
CodeEditSourceEditor (
108
110
codeFile. content ?? NSTextStorage ( ) ,
109
111
language: getLanguage ( ) ,
110
- theme: selectedTheme . editor. editorTheme,
112
+ theme: currentTheme . editor. editorTheme,
111
113
font: font,
112
114
tabWidth: codeFile. defaultTabWidth ?? defaultTabWidth,
113
115
indentOption: ( codeFile. indentOption ?? indentOption) . textViewOption ( ) ,
@@ -131,17 +133,9 @@ struct CodeFileView: View {
131
133
EffectView ( . contentBackground)
132
134
}
133
135
}
134
- . colorScheme (
135
- selectedTheme. appearance == . dark
136
- ? . dark
137
- : . light
138
- )
136
+ . colorScheme ( currentTheme. appearance == . dark ? . dark : . light)
139
137
// minHeight zero fixes a bug where the app would freeze if the contents of the file are empty.
140
138
. frame ( minHeight: . zero, maxHeight: . infinity)
141
- . onChange ( of: themeModel. selectedTheme) { newValue in
142
- guard let theme = newValue else { return }
143
- self . selectedTheme = theme
144
- }
145
139
. onChange ( of: settingsFont) { newFontSetting in
146
140
font = newFontSetting. current
147
141
}
@@ -162,10 +156,12 @@ struct CodeFileView: View {
162
156
}
163
157
164
158
private func getBracketPairHighlight( ) -> BracketPairHighlight ? {
165
- let theme = ThemeModel . shared. selectedTheme ?? ThemeModel . shared. themes. first!
166
- let color = Settings [ \. textEditing] . bracketHighlight. useCustomColor
167
- ? Settings [ \. textEditing] . bracketHighlight. color. nsColor
168
- : theme. editor. text. nsColor. withAlphaComponent ( 0.8 )
159
+ let color = if Settings [ \. textEditing] . bracketHighlight. useCustomColor {
160
+ Settings [ \. textEditing] . bracketHighlight. color. nsColor
161
+ } else {
162
+ currentTheme. editor. text. nsColor. withAlphaComponent ( 0.8 )
163
+ }
164
+
169
165
switch Settings [ \. textEditing] . bracketHighlight. highlightType {
170
166
case . disabled:
171
167
return nil
0 commit comments