Skip to content

Commit b8433c1

Browse files
committed
Support changing code font of suggestion, chat and prompt to code
1 parent e9525da commit b8433c1

File tree

14 files changed

+127
-126
lines changed

14 files changed

+127
-126
lines changed

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ struct ChatPanel_EmptyChat_Preview: PreviewProvider {
533533

534534
struct ChatCodeSyntaxHighlighter: CodeSyntaxHighlighter {
535535
let brightMode: Bool
536-
let fontSize: Double
536+
let font: NSFont
537537
let colorChange: Color?
538538

539-
init(brightMode: Bool, fontSize: Double, colorChange: Color?) {
539+
init(brightMode: Bool, font: NSFont, colorChange: Color?) {
540540
self.brightMode = brightMode
541-
self.fontSize = fontSize
541+
self.font = font
542542
self.colorChange = colorChange
543543
}
544544

@@ -548,7 +548,7 @@ struct ChatCodeSyntaxHighlighter: CodeSyntaxHighlighter {
548548
language: language ?? "",
549549
scenario: "chat",
550550
brightMode: brightMode,
551-
fontSize: fontSize
551+
font: font
552552
)
553553
return Text(AttributedString(content))
554554
}

Core/Sources/ChatGPTChatTab/Styles.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct ThemedMarkdownText: View {
8181
@AppStorage(\.codeForegroundColorDark) var codeForegroundColorDark
8282
@AppStorage(\.codeBackgroundColorDark) var codeBackgroundColorDark
8383
@AppStorage(\.chatFontSize) var chatFontSize
84-
@AppStorage(\.chatCodeFontSize) var chatCodeFontSize
84+
@AppStorage(\.chatCodeFont) var chatCodeFont
8585
@Environment(\.colorScheme) var colorScheme
8686

8787
let text: String
@@ -122,7 +122,7 @@ struct ThemedMarkdownText: View {
122122
.markdownCodeSyntaxHighlighter(
123123
ChatCodeSyntaxHighlighter(
124124
brightMode: colorScheme != .dark,
125-
fontSize: chatCodeFontSize,
125+
font: chatCodeFont.value.nsFont,
126126
colorChange: colorScheme == .dark
127127
? codeForegroundColorDark.value?.swiftUIColor
128128
: codeForegroundColorLight.value?.swiftUIColor

Core/Sources/HostApp/FeatureSettings/ChatSettingsView.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct ChatSettingsView: View {
1313
@AppStorage(\.chatGPTTemperature) var chatGPTTemperature
1414
@AppStorage(\.chatGPTMaxMessageCount) var chatGPTMaxMessageCount
1515
@AppStorage(\.chatFontSize) var chatFontSize
16-
@AppStorage(\.chatCodeFontSize) var chatCodeFontSize
16+
@AppStorage(\.chatCodeFont) var chatCodeFont
1717

1818
@AppStorage(\.defaultChatFeatureChatModelId) var defaultChatFeatureChatModelId
1919
@AppStorage(\.defaultChatSystemPrompt) var defaultChatSystemPrompt
@@ -150,17 +150,8 @@ struct ChatSettingsView: View {
150150
Text("pt")
151151
}
152152

153-
HStack {
154-
TextField(text: .init(get: {
155-
"\(Int(settings.chatCodeFontSize))"
156-
}, set: {
157-
settings.chatCodeFontSize = Double(Int($0) ?? 0)
158-
})) {
159-
Text("Font size of code block")
160-
}
161-
.textFieldStyle(.roundedBorder)
162-
163-
Text("pt")
153+
FontPicker(font: $settings.chatCodeFont) {
154+
Text("Font of code")
164155
}
165156

166157
Toggle(isOn: $settings.wrapCodeInCodeBlock) {

Core/Sources/HostApp/FeatureSettings/PromptToCodeSettingsView.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ struct PromptToCodeSettingsView: View {
1010
final class Settings: ObservableObject {
1111
@AppStorage(\.hideCommonPrecedingSpacesInPromptToCode)
1212
var hideCommonPrecedingSpaces
13-
@AppStorage(\.promptToCodeCodeFontSize)
14-
var fontSize
13+
@AppStorage(\.promptToCodeCodeFont)
14+
var font
1515
@AppStorage(\.promptToCodeGenerateDescription)
1616
var promptToCodeGenerateDescription
1717
@AppStorage(\.promptToCodeGenerateDescriptionInUserPreferredLanguage)
@@ -91,24 +91,15 @@ struct PromptToCodeSettingsView: View {
9191
Text("Hide Common Preceding Spaces")
9292
}
9393

94-
HStack {
95-
TextField(text: .init(get: {
96-
"\(Int(settings.fontSize))"
97-
}, set: {
98-
settings.fontSize = Double(Int($0) ?? 0)
99-
})) {
100-
Text("Font size of suggestion code")
101-
}
102-
.textFieldStyle(.roundedBorder)
103-
104-
Text("pt")
105-
}
106-
10794
#if canImport(ProHostApp)
10895

10996
CodeHighlightThemePicker(scenario: .promptToCode)
11097

11198
#endif
99+
100+
FontPicker(font: $settings.font) {
101+
Text("Font")
102+
}
112103
}
113104

114105
ScopeForm()

Core/Sources/HostApp/FeatureSettings/SuggestionSettingsView.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct SuggestionSettingsView: View {
4646
var suggestionFeatureEnabledProjectList
4747
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion)
4848
var hideCommonPrecedingSpacesInSuggestion
49-
@AppStorage(\.suggestionCodeFontSize)
50-
var suggestionCodeFontSize
49+
@AppStorage(\.suggestionCodeFont)
50+
var font
5151
@AppStorage(\.suggestionFeatureProvider)
5252
var suggestionFeatureProvider
5353
@AppStorage(\.suggestionDisplayCompactMode)
@@ -247,24 +247,15 @@ struct SuggestionSettingsView: View {
247247
Text("Hide Common Preceding Spaces")
248248
}
249249

250-
HStack {
251-
TextField(text: .init(get: {
252-
"\(Int(settings.suggestionCodeFontSize))"
253-
}, set: {
254-
settings.suggestionCodeFontSize = Double(Int($0) ?? 0)
255-
})) {
256-
Text("Font size of suggestion code")
257-
}
258-
.textFieldStyle(.roundedBorder)
259-
260-
Text("pt")
261-
}
262-
263250
#if canImport(ProHostApp)
264251

265252
CodeHighlightThemePicker(scenario: .suggestion)
266-
253+
267254
#endif
255+
256+
FontPicker(font: $settings.font) {
257+
Text("Font")
258+
}
268259
}
269260
}
270261
}

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
struct CodeBlockSuggestionPanel: View {
55
@ObservedObject var suggestion: CodeSuggestionProvider
66
@Environment(\.colorScheme) var colorScheme
7-
@AppStorage(\.suggestionCodeFontSize) var fontSize
7+
@AppStorage(\.suggestionCodeFont) var codeFont
88
@AppStorage(\.suggestionDisplayCompactMode) var suggestionDisplayCompactMode
99
@AppStorage(\.suggestionPresentationMode) var suggestionPresentationMode
1010
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpaces
@@ -108,7 +108,7 @@ struct CodeBlockSuggestionPanel: View {
108108
startLineIndex: suggestion.startLineIndex,
109109
scenario: "suggestion",
110110
colorScheme: colorScheme,
111-
fontSize: fontSize,
111+
font: codeFont.value.nsFont,
112112
droppingLeadingSpaces: hideCommonPrecedingSpaces,
113113
proposedForegroundColor: {
114114
if syncHighlightTheme {

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ extension PromptToCodePanel {
202202
struct Content: View {
203203
let store: StoreOf<PromptToCode>
204204
@Environment(\.colorScheme) var colorScheme
205-
@AppStorage(\.promptToCodeCodeFontSize) var fontSize
205+
@AppStorage(\.promptToCodeCodeFont) var codeFont
206206
@AppStorage(\.hideCommonPrecedingSpacesInPromptToCode) var hideCommonPrecedingSpaces
207207
@AppStorage(\.syncPromptToCodeHighlightTheme) var syncHighlightTheme
208208
@AppStorage(\.codeForegroundColorLight) var codeForegroundColorLight
@@ -312,7 +312,7 @@ extension PromptToCodePanel {
312312
colorScheme: colorScheme,
313313
firstLinePrecedingSpaceCount: viewStore.state
314314
.firstLinePrecedingSpaceCount,
315-
fontSize: fontSize,
315+
font: codeFont.value.nsFont,
316316
droppingLeadingSpaces: hideCommonPrecedingSpaces,
317317
proposedForegroundColor:codeForegroundColor
318318
)

Pro

Submodule Pro updated from 43e5416 to 5207bbf

Tool/Sources/Preferences/Keys.swift

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public struct UserDefaultPreferenceKeys {
9393
defaultValue: false,
9494
key: "ShowHideWidgetShortcutGlobally"
9595
)
96-
96+
9797
// MARK: Update Channel
98-
98+
9999
public let installBetaBuilds = PreferenceKey(
100100
defaultValue: false,
101101
key: "InstallBetaBuilds"
@@ -163,7 +163,7 @@ public extension UserDefaultPreferenceKeys {
163163
var gitHubCopilotProxyPort: PreferenceKey<String> {
164164
.init(defaultValue: "", key: "GitHubCopilotProxyPort")
165165
}
166-
166+
167167
var gitHubCopilotEnterpriseURI: PreferenceKey<String> {
168168
.init(defaultValue: "", key: "GitHubCopilotEnterpriseURI")
169169
}
@@ -290,15 +290,15 @@ public extension UserDefaultPreferenceKeys {
290290
var promptToCodeEmbeddingModelId: PreferenceKey<String> {
291291
.init(defaultValue: "", key: "PromptToCodeEmbeddingModelId")
292292
}
293-
293+
294294
var enableSenseScopeByDefaultInPromptToCode: PreferenceKey<Bool> {
295295
.init(defaultValue: false, key: "EnableSenseScopeByDefaultInPromptToCode")
296296
}
297-
297+
298298
var promptToCodeCodeFontSize: PreferenceKey<Double> {
299299
.init(defaultValue: 13, key: "PromptToCodeCodeFontSize")
300300
}
301-
301+
302302
var hideCommonPrecedingSpacesInPromptToCode: PreferenceKey<Bool> {
303303
.init(defaultValue: true, key: "HideCommonPrecedingSpacesInPromptToCode")
304304
}
@@ -310,7 +310,7 @@ public extension UserDefaultPreferenceKeys {
310310
var oldSuggestionFeatureProvider: DeprecatedPreferenceKey<BuiltInSuggestionFeatureProvider> {
311311
.init(defaultValue: .gitHubCopilot, key: "SuggestionFeatureProvider")
312312
}
313-
313+
314314
var suggestionFeatureProvider: PreferenceKey<SuggestionFeatureProvider> {
315315
.init(defaultValue: .builtIn(.gitHubCopilot), key: "NewSuggestionFeatureProvider")
316316
}
@@ -354,11 +354,11 @@ public extension UserDefaultPreferenceKeys {
354354
var acceptSuggestionWithTab: PreferenceKey<Bool> {
355355
.init(defaultValue: true, key: "AcceptSuggestionWithTab")
356356
}
357-
357+
358358
var dismissSuggestionWithEsc: PreferenceKey<Bool> {
359359
.init(defaultValue: true, key: "DismissSuggestionWithEsc")
360360
}
361-
361+
362362
var isSuggestionSenseEnabled: PreferenceKey<Bool> {
363363
.init(defaultValue: false, key: "IsSuggestionSenseEnabled")
364364
}
@@ -449,15 +449,15 @@ public extension UserDefaultPreferenceKeys {
449449
var enableWebScopeByDefaultInChatContext: PreferenceKey<Bool> {
450450
.init(defaultValue: false, key: "EnableWebScopeByDefaultInChatContext")
451451
}
452-
452+
453453
var preferredChatModelIdForSenseScope: PreferenceKey<String> {
454454
.init(defaultValue: "", key: "PreferredChatModelIdForSenseScope")
455455
}
456-
456+
457457
var preferredChatModelIdForProjectScope: PreferenceKey<String> {
458458
.init(defaultValue: "", key: "PreferredChatModelIdForProjectScope")
459459
}
460-
460+
461461
var preferredChatModelIdForWebScope: PreferenceKey<String> {
462462
.init(defaultValue: "", key: "PreferredChatModelIdForWebScope")
463463
}
@@ -477,33 +477,42 @@ public extension UserDefaultPreferenceKeys {
477477
var syncChatCodeHighlightTheme: PreferenceKey<Bool> {
478478
.init(defaultValue: false, key: "SyncChatCodeHighlightTheme")
479479
}
480-
480+
481481
var codeForegroundColorLight: PreferenceKey<UserDefaultsStorageBox<StorableColor?>> {
482482
.init(defaultValue: .init(nil), key: "CodeForegroundColorLight")
483483
}
484-
484+
485485
var codeForegroundColorDark: PreferenceKey<UserDefaultsStorageBox<StorableColor?>> {
486486
.init(defaultValue: .init(nil), key: "CodeForegroundColorDark")
487487
}
488-
488+
489489
var codeBackgroundColorLight: PreferenceKey<UserDefaultsStorageBox<StorableColor?>> {
490490
.init(defaultValue: .init(nil), key: "CodeBackgroundColorLight")
491491
}
492-
492+
493493
var codeBackgroundColorDark: PreferenceKey<UserDefaultsStorageBox<StorableColor?>> {
494494
.init(defaultValue: .init(nil), key: "CodeBackgroundColorDark")
495495
}
496-
497-
var suggestionFont: PreferenceKey<UserDefaultsStorageBox<StorableFont?>> {
498-
.init(defaultValue: .init(nil), key: "SuggestionFont")
496+
497+
var suggestionCodeFont: PreferenceKey<UserDefaultsStorageBox<StorableFont>> {
498+
.init(
499+
defaultValue: .init(.init(nsFont: .monospacedSystemFont(ofSize: 12, weight: .regular))),
500+
key: "SuggestionCodeFont"
501+
)
499502
}
500-
501-
var promptToCodeFont: PreferenceKey<UserDefaultsStorageBox<StorableFont?>> {
502-
.init(defaultValue: .init(nil), key: "promptToCodeFont")
503+
504+
var promptToCodeCodeFont: PreferenceKey<UserDefaultsStorageBox<StorableFont>> {
505+
.init(
506+
defaultValue: .init(.init(nsFont: .monospacedSystemFont(ofSize: 12, weight: .regular))),
507+
key: "promptToCodeCodeFont"
508+
)
503509
}
504-
505-
var chatCodeFont: PreferenceKey<UserDefaultsStorageBox<StorableFont?>> {
506-
.init(defaultValue: .init(nil), key: "chatCodeFont")
510+
511+
var chatCodeFont: PreferenceKey<UserDefaultsStorageBox<StorableFont>> {
512+
.init(
513+
defaultValue: .init(.init(nsFont: .monospacedSystemFont(ofSize: 12, weight: .regular))),
514+
key: "chatCodeFont"
515+
)
507516
}
508517
}
509518

@@ -620,11 +629,11 @@ public extension UserDefaultPreferenceKeys {
620629
key: "FeatureFlag-DisableGitHubCopilotSettingsAutoRefreshOnAppear"
621630
)
622631
}
623-
632+
624633
var disableGitIgnoreCheck: FeatureFlag {
625634
.init(defaultValue: false, key: "FeatureFlag-DisableGitIgnoreCheck")
626635
}
627-
636+
628637
var disableFileContentManipulationByCheatsheet: FeatureFlag {
629638
.init(defaultValue: true, key: "FeatureFlag-DisableFileContentManipulationByCheatsheet")
630639
}
@@ -635,32 +644,32 @@ public extension UserDefaultPreferenceKeys {
635644
key: "FeatureFlag-DisableEnhancedWorkspace"
636645
)
637646
}
638-
647+
639648
var restartXcodeInspectorIfAccessibilityAPIIsMalfunctioning: FeatureFlag {
640649
.init(
641650
defaultValue: false,
642651
key: "FeatureFlag-RestartXcodeInspectorIfAccessibilityAPIIsMalfunctioning"
643652
)
644653
}
645-
654+
646655
var restartXcodeInspectorIfAccessibilityAPIIsMalfunctioningNoTimer: FeatureFlag {
647656
.init(
648657
defaultValue: true,
649658
key: "FeatureFlag-RestartXcodeInspectorIfAccessibilityAPIIsMalfunctioningNoTimer"
650659
)
651660
}
652-
661+
653662
var toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted: FeatureFlag {
654663
.init(
655664
defaultValue: false,
656665
key: "FeatureFlag-ToastForTheReasonWhyXcodeInspectorNeedsToBeRestarted"
657666
)
658667
}
659-
668+
660669
var observeToAXNotificationWithDefaultMode: FeatureFlag {
661670
.init(defaultValue: false, key: "FeatureFlag-observeToAXNotificationWithDefaultMode")
662671
}
663-
672+
664673
var useCloudflareDomainNameForLicenseCheck: FeatureFlag {
665674
.init(defaultValue: false, key: "FeatureFlag-UseCloudflareDomainNameForLicenseCheck")
666675
}

Tool/Sources/Preferences/UserDefaults.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public extension UserDefaults {
3131
defaultValue: shared.value(for: \.suggestionCodeFontSize)
3232
)
3333
shared.setupDefaultValue(
34-
for: \.suggestionFont,
34+
for: \.suggestionCodeFont,
3535
defaultValue: .init(.init(nsFont: .monospacedSystemFont(
3636
ofSize: shared.value(for: \.suggestionCodeFontSize),
3737
weight: .regular
3838
)))
3939
)
4040
shared.setupDefaultValue(
41-
for: \.promptToCodeFont,
41+
for: \.promptToCodeCodeFont,
4242
defaultValue: .init(.init(nsFont: .monospacedSystemFont(
4343
ofSize: shared.value(for: \.promptToCodeCodeFontSize),
4444
weight: .regular

0 commit comments

Comments
 (0)