Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Copilot for Xcode/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions Core/Sources/Preferences/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
121 changes: 70 additions & 51 deletions Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
6 changes: 5 additions & 1 deletion Core/Sources/SuggestionWidget/SyntaxHighlighting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down