diff --git a/Copilot for Xcode/SettingsView.swift b/Copilot for Xcode/SettingsView.swift index 7160d5a2..42aabbe7 100644 --- a/Copilot for Xcode/SettingsView.swift +++ b/Copilot for Xcode/SettingsView.swift @@ -25,6 +25,7 @@ struct SettingsView: View { @State var editingRealtimeSuggestionDebounce: Double = UserDefaults.shared .value(for: \.realtimeSuggestionDebounce) @Environment(\.updateChecker) var updateChecker + @AppStorage(\.codeFontSize) var codeFontSize: String var body: some View { Section { @@ -114,6 +115,11 @@ struct SettingsView: View { Text("Use accessibility API to accept suggestion in widget") } .toggleStyle(.switch) + HStack { + Text("SuggestionCodeFontSize") + TextField("(default:13)", text: $codeFontSize) + .textFieldStyle(.copilot) + } } }.buttonStyle(.copilot) } diff --git a/Core/Sources/Preferences/Keys.swift b/Core/Sources/Preferences/Keys.swift index a0c7c1bf..a7b0bc88 100644 --- a/Core/Sources/Preferences/Keys.swift +++ b/Core/Sources/Preferences/Keys.swift @@ -136,6 +136,12 @@ public struct UserDefaultPreferenceKeys { public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() } public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() } + + public struct RealtimeSuggestionCodeFontSize: UserDefaultPreferenceKey { + public let defaultValue: String = "13" + public let key = "RealtimeSuggestionCodeFontSize" + } + public var codeFontSize: RealtimeSuggestionCodeFontSize { .init() } } public enum FeatureFlags { diff --git a/Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift b/Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift index 0c4167ed..222e38db 100644 --- a/Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift +++ b/Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift @@ -57,6 +57,74 @@ struct ChatPanelToolbar: View { } } +struct UserMessageView: View { + var message: ChatMessage + @Environment(\.colorScheme) var colorScheme + var r = 6 as Double + + var body: some View { + let text = message.text.isEmpty ? "..." : message.text + Markdown(text) + .textSelection(.enabled) + .markdownTheme(.gitHub.text { + BackgroundColor(Color.clear) + }) + .markdownCodeSyntaxHighlighter( + ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark) + ) + .frame(alignment: .trailing) + .padding() + .background { + RoundedCorners(tl: r, bl: r, br: r * 1.5) + .fill(Color.userChatContentBackground) + } + .overlay { + RoundedCorners(tl: r, bl: r, br: r * 1.5) + .stroke(Color(nsColor: .separatorColor), lineWidth: 1) + } + .padding(.leading) + .padding(.trailing, 8) + .rotationEffect(Angle(degrees: 180)) + .scaleEffect(x: -1, y: 1, anchor: .center) + .shadow(color: .black.opacity(0.1), radius: 2) + .frame(maxWidth: .infinity, alignment: .trailing) + } +} + +struct NonUserMessageView: View { + var message: ChatMessage + @Environment(\.colorScheme) var colorScheme + var r = 6 as Double + + var body: some View { + let text = message.text.isEmpty ? "..." : message.text + Markdown(text) + .textSelection(.enabled) + .markdownTheme(.gitHub.text { + BackgroundColor(Color.clear) + }) + .markdownCodeSyntaxHighlighter( + ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark) + ) + .frame(alignment: .leading) + .padding() + .background { + RoundedCorners(tr: r, bl: r * 1.5, br: r) + .fill(Color.contentBackground) + } + .overlay { + RoundedCorners(tr: r, bl: r * 1.5, br: r) + .stroke(Color(nsColor: .separatorColor), lineWidth: 1) + } + .padding(.leading, 8) + .padding(.trailing) + .rotationEffect(Angle(degrees: 180)) + .scaleEffect(x: -1, y: 1, anchor: .center) + .shadow(color: .black.opacity(0.1), radius: 2) + .frame(maxWidth: .infinity, alignment: .leading) + } +} + struct ChatPanelMessages: View { @ObservedObject var chat: ChatProvider var inputAreaNamespace: Namespace.ID @@ -116,59 +184,10 @@ struct ChatPanelMessages: View { } ForEach(chat.history.reversed(), id: \.id) { message in - let text = message.text.isEmpty && !message.isUser ? "..." : message - .text - if message.isUser { - Markdown(text) - .textSelection(.enabled) - .markdownTheme(.gitHub.text { - BackgroundColor(Color.clear) - }) - .markdownCodeSyntaxHighlighter( - ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark) - ) - .frame(alignment: .trailing) - .padding() - .background { - RoundedCorners(tl: r, bl: r, br: r * 1.5) - .fill(Color.userChatContentBackground) - } - .overlay { - RoundedCorners(tl: r, bl: r, br: r * 1.5) - .stroke(Color(nsColor: .separatorColor), lineWidth: 1) - } - .padding(.leading) - .padding(.trailing, 8) - .rotationEffect(Angle(degrees: 180)) - .scaleEffect(x: -1, y: 1, anchor: .center) - .shadow(color: .black.opacity(0.1), radius: 2) - .frame(maxWidth: .infinity, alignment: .trailing) + UserMessageView(message: message) } else { - Markdown(text) - .textSelection(.enabled) - .markdownTheme(.gitHub.text { - BackgroundColor(Color.clear) - }) - .markdownCodeSyntaxHighlighter( - ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark) - ) - .frame(alignment: .leading) - .padding() - .background { - RoundedCorners(tr: r, bl: r * 1.5, br: r) - .fill(Color.contentBackground) - } - .overlay { - RoundedCorners(tr: r, bl: r * 1.5, br: r) - .stroke(Color(nsColor: .separatorColor), lineWidth: 1) - } - .padding(.leading, 8) - .padding(.trailing) - .rotationEffect(Angle(degrees: 180)) - .scaleEffect(x: -1, y: 1, anchor: .center) - .shadow(color: .black.opacity(0.1), radius: 2) - .frame(maxWidth: .infinity, alignment: .leading) + NonUserMessageView(message: message) } } diff --git a/Core/Sources/SuggestionWidget/SyntaxHighlighting.swift b/Core/Sources/SuggestionWidget/SyntaxHighlighting.swift index 22fe0de5..772d1f8a 100644 --- a/Core/Sources/SuggestionWidget/SyntaxHighlighting.swift +++ b/Core/Sources/SuggestionWidget/SyntaxHighlighting.swift @@ -110,11 +110,15 @@ func highlighted( brightMode: Bool, droppingLeadingSpaces: Bool ) -> (code: [NSAttributedString], commonLeadingSpaceCount: Int) { + var fontSize: Double = 13 + if let size = Double(UserDefaults.shared.value(for: \.codeFontSize)) { + fontSize = size + } let formatted = highlightedCodeBlock( code: code, language: language, brightMode: brightMode, - fontSize: 13 + fontSize: fontSize ) let middleDotColor = brightMode ? NSColor.black.withAlphaComponent(0.1)