Skip to content

Commit bda9940

Browse files
Bold and italic text formatting in themes (#1893)
* Added bold and italic to themes * Corrected key names in basic theme
1 parent e4f03fe commit bda9940

22 files changed

+131
-35
lines changed

Diff for: CodeEdit/Features/Settings/Pages/TextEditingSettings/Models/TextEditingSettings.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extension SettingsData {
158158
var highlightType: HighlightType = .flash
159159
var useCustomColor: Bool = false
160160
/// The color to use for the highlight.
161-
var color: Theme.Attributes = Theme.Attributes(color: "FFFFFF")
161+
var color: Theme.Attributes = Theme.Attributes(color: "FFFFFF", bold: false, italic: false)
162162

163163
enum HighlightType: String, Codable {
164164
case disabled

Diff for: CodeEdit/Features/Settings/Pages/ThemeSettings/Models/Theme.swift

+31-1
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,39 @@ extension Theme {
112112

113113
/// The 24-bit hex string of the color (e.g. #123456)
114114
var color: String
115+
var bold: Bool
116+
var italic: Bool
115117

116-
init(color: String) {
118+
init(color: String, bold: Bool = false, italic: Bool = false) {
117119
self.color = color
120+
self.bold = bold
121+
self.italic = italic
122+
}
123+
124+
init(from decoder: Decoder) throws {
125+
let container = try decoder.container(keyedBy: CodingKeys.self)
126+
self.color = try container.decode(String.self, forKey: .color)
127+
self.bold = try container.decodeIfPresent(Bool.self, forKey: .bold) ?? false
128+
self.italic = try container.decodeIfPresent(Bool.self, forKey: .italic) ?? false
129+
}
130+
131+
func encode(to encoder: Encoder) throws {
132+
var container = encoder.container(keyedBy: CodingKeys.self)
133+
try container.encode(color, forKey: .color)
134+
135+
if bold {
136+
try container.encode(bold, forKey: .bold)
137+
}
138+
139+
if italic {
140+
try container.encode(italic, forKey: .italic)
141+
}
142+
}
143+
144+
enum CodingKeys: String, CodingKey {
145+
case color
146+
case bold
147+
case italic
118148
}
119149

120150
/// The `SwiftUI` of ``color``

Diff for: CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsThemeDetails.swift

+30-10
Original file line numberDiff line numberDiff line change
@@ -71,52 +71,72 @@ struct ThemeSettingsThemeDetails: View {
7171
VStack(spacing: 0) {
7272
ThemeSettingsThemeToken(
7373
"Keywords",
74-
color: $theme.editor.keywords.swiftColor
74+
color: $theme.editor.keywords.swiftColor,
75+
bold: $theme.editor.keywords.bold,
76+
italic: $theme.editor.keywords.italic
7577
)
7678
Divider().padding(.horizontal, 10)
7779
ThemeSettingsThemeToken(
7880
"Commands",
79-
color: $theme.editor.commands.swiftColor
81+
color: $theme.editor.commands.swiftColor,
82+
bold: $theme.editor.commands.bold,
83+
italic: $theme.editor.commands.italic
8084
)
8185
Divider().padding(.horizontal, 10)
8286
ThemeSettingsThemeToken(
8387
"Types",
84-
color: $theme.editor.types.swiftColor
88+
color: $theme.editor.types.swiftColor,
89+
bold: $theme.editor.types.bold,
90+
italic: $theme.editor.types.italic
8591
)
8692
Divider().padding(.horizontal, 10)
8793
ThemeSettingsThemeToken(
8894
"Attributes",
89-
color: $theme.editor.attributes.swiftColor
95+
color: $theme.editor.attributes.swiftColor,
96+
bold: $theme.editor.attributes.bold,
97+
italic: $theme.editor.attributes.italic
9098
)
9199
Divider().padding(.horizontal, 10)
92100
ThemeSettingsThemeToken(
93101
"Variables",
94-
color: $theme.editor.variables.swiftColor
102+
color: $theme.editor.variables.swiftColor,
103+
bold: $theme.editor.variables.bold,
104+
italic: $theme.editor.variables.italic
95105
)
96106
Divider().padding(.horizontal, 10)
97107
ThemeSettingsThemeToken(
98108
"Values",
99-
color: $theme.editor.values.swiftColor
109+
color: $theme.editor.values.swiftColor,
110+
bold: $theme.editor.values.bold,
111+
italic: $theme.editor.values.italic
100112
)
101113
Divider().padding(.horizontal, 10)
102114
ThemeSettingsThemeToken(
103115
"Numbers",
104-
color: $theme.editor.numbers.swiftColor
116+
color: $theme.editor.numbers.swiftColor,
117+
bold: $theme.editor.numbers.bold,
118+
italic: $theme.editor.numbers.italic
105119
)
106120
Divider().padding(.horizontal, 10)
107121
ThemeSettingsThemeToken(
108122
"Strings",
109-
color: $theme.editor.strings.swiftColor
123+
color: $theme.editor.strings.swiftColor,
124+
bold: $theme.editor.strings.bold,
125+
italic: $theme.editor.strings.italic
110126
)
111127
Divider().padding(.horizontal, 10)
112128
ThemeSettingsThemeToken(
113129
"Characters",
114-
color: $theme.editor.characters.swiftColor
130+
color: $theme.editor.characters.swiftColor,
131+
bold: $theme.editor.characters.bold,
132+
italic: $theme.editor.characters.italic
115133
)
116134
Divider().padding(.horizontal, 10)
117135
ThemeSettingsThemeToken(
118136
"Comments",
119-
color: $theme.editor.comments.swiftColor
137+
color: $theme.editor.comments.swiftColor,
138+
bold: $theme.editor.comments.bold,
139+
italic: $theme.editor.comments.italic
120140
)
121141
}
122142
.background(theme.editor.background.swiftColor)

Diff for: CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsThemeToken.swift

+31-3
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,53 @@ struct ThemeSettingsThemeToken: View {
1111
var label: String
1212

1313
@Binding var color: Color
14+
@Binding var bold: Bool
15+
@Binding var italic: Bool
1416

1517
@State private var selectedColor: Color
18+
@State private var isHovering = false
1619

17-
init(_ label: String, color: Binding<Color>) {
20+
init(_ label: String, color: Binding<Color>, bold: Binding<Bool>, italic: Binding<Bool>) {
1821
self.label = label
1922
self._color = color
23+
self._bold = bold
24+
self._italic = italic
2025
self._selectedColor = State(initialValue: color.wrappedValue)
2126
}
2227

2328
var body: some View {
2429
LabeledContent {
25-
ColorPicker(selection: $selectedColor, supportsOpacity: false) { }
26-
.labelsHidden()
30+
HStack(spacing: 20) {
31+
HStack(spacing: 8) {
32+
Toggle(isOn: $bold) {
33+
Image(systemName: "bold")
34+
}
35+
.toggleStyle(.icon)
36+
.help("Bold")
37+
Divider()
38+
.fixedSize()
39+
Toggle(isOn: $italic) {
40+
Image(systemName: "italic")
41+
}
42+
.toggleStyle(.icon)
43+
.help("Italic")
44+
}
45+
.opacity(isHovering || bold || italic ? 1 : 0)
46+
47+
ColorPicker(selection: $selectedColor, supportsOpacity: false) { }
48+
.labelsHidden()
49+
}
2750
} label: {
2851
Text(label)
2952
.font(.system(.body, design: .monospaced))
53+
.bold(bold)
54+
.italic(italic)
3055
.foregroundStyle(color)
3156
}
3257
.padding(10)
58+
.onHover { hovering in
59+
isHovering = hovering
60+
}
3361
.onChange(of: selectedColor) { newValue in
3462
color = newValue
3563
}

Diff for: DefaultThemes/Basic.cetheme

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"id": "basic",
3-
"name": "Basic",
2+
"name": "basic",
3+
"displayName": "Basic",
44
"description": "CodeEdit bundled theme.",
55
"author": "CodeEdit",
66
"version": "0.0.1",
@@ -39,7 +39,8 @@
3939
"color": "#000000"
4040
},
4141
"keywords": {
42-
"color": "#0433FF"
42+
"color": "#0433FF",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#000000"

Diff for: DefaultThemes/Civic.cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#00AAA3"
4040
},
4141
"keywords": {
42-
"color": "#E12DA0"
42+
"color": "#E12DA0",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#68878F"

Diff for: DefaultThemes/Classic (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#D9C97C"
4040
},
4141
"keywords": {
42-
"color": "#FF7AB2"
42+
"color": "#FF7AB2",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#CC9768"

Diff for: DefaultThemes/Classic (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#272AD8"
4040
},
4141
"keywords": {
42-
"color": "#AD3DA4"
42+
"color": "#AD3DA4",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#947100"

Diff for: DefaultThemes/Default (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#D9C97C"
4040
},
4141
"keywords": {
42-
"color": "#FF7AB2"
42+
"color": "#FF7AB2",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#CC9768"

Diff for: DefaultThemes/Default (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#272AD8"
4040
},
4141
"keywords": {
42-
"color": "#AD3DA4"
42+
"color": "#AD3DA4",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#947100"

Diff for: DefaultThemes/Dusk.cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#8B84CF"
4040
},
4141
"keywords": {
42-
"color": "#C2349B"
42+
"color": "#C2349B",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#67878F"

Diff for: DefaultThemes/GitHub (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#79C0FF"
4040
},
4141
"keywords": {
42-
"color": "#FF7B72"
42+
"color": "#FF7B72",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#79C0FF"

Diff for: DefaultThemes/GitHub (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#0550AE"
4040
},
4141
"keywords": {
42-
"color": "#CF222E"
42+
"color": "#CF222E",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#0550AE"

Diff for: DefaultThemes/High Contrast (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#D9C668"
4040
},
4141
"keywords": {
42-
"color": "#FF85B8"
42+
"color": "#FF85B8",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#E8B68B"

Diff for: DefaultThemes/High Contrast (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#272AD8"
4040
},
4141
"keywords": {
42-
"color": "#9C2191"
42+
"color": "#9C2191",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#6E5400"

Diff for: DefaultThemes/Low Key.cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#323E7D"
4040
},
4141
"keywords": {
42-
"color": "#323E7D"
42+
"color": "#323E7D",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#255E22"

Diff for: DefaultThemes/Midnight.cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#8B87FF"
4040
},
4141
"keywords": {
42-
"color": "#DE38A6"
42+
"color": "#DE38A6",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#3B5AAB"

Diff for: DefaultThemes/Presentation (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#FFEA80"
4040
},
4141
"keywords": {
42-
"color": "#F7439D"
42+
"color": "#F7439D",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#E7AD78"

Diff for: DefaultThemes/Presentation (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#0435FF"
4040
},
4141
"keywords": {
42-
"color": "#C32275"
42+
"color": "#C32275",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#967E34"

Diff for: DefaultThemes/Solarized (Dark).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#DC322F"
4040
},
4141
"keywords": {
42-
"color": "#859900"
42+
"color": "#859900",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#6C71C4"

Diff for: DefaultThemes/Solarized (Light).cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#DC322F"
4040
},
4141
"keywords": {
42-
"color": "#859900"
42+
"color": "#859900",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#6C71C4"

Diff for: DefaultThemes/Sunset.cetheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"color": "#35568A"
4040
},
4141
"keywords": {
42-
"color": "#35568A"
42+
"color": "#35568A",
43+
"bold": true
4344
},
4445
"attributes": {
4546
"color": "#3A48AD"

0 commit comments

Comments
 (0)