forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserMessage.swift
More file actions
86 lines (78 loc) · 2.52 KB
/
UserMessage.swift
File metadata and controls
86 lines (78 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import ComposableArchitecture
import Foundation
import MarkdownUI
import SwiftUI
struct UserMessage: View {
var r: Double { messageBubbleCornerRadius }
let id: String
let text: String
let chat: StoreOf<Chat>
@Environment(\.colorScheme) var colorScheme
@AppStorage(\.chatFontSize) var chatFontSize
@AppStorage(\.chatCodeFontSize) var chatCodeFontSize
var body: some View {
Markdown(text)
.textSelection(.enabled)
.markdownTheme(.custom(fontSize: chatFontSize))
.markdownCodeSyntaxHighlighter(
ChatCodeSyntaxHighlighter(
brightMode: colorScheme != .dark,
fontSize: chatCodeFontSize
)
)
.frame(alignment: .leading)
.padding()
.background {
RoundedCorners(tl: r, tr: r, bl: r, br: 0)
.fill(Color.userChatContentBackground)
}
.overlay {
RoundedCorners(tl: r, tr: r, bl: r, br: 0)
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
}
.padding(.leading)
.padding(.trailing, 8)
.shadow(color: .black.opacity(0.1), radius: 2)
.frame(maxWidth: .infinity, alignment: .trailing)
.contextMenu {
Button("Copy") {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
}
Button("Send Again") {
chat.send(.resendMessageButtonTapped(id))
}
Button("Set as Extra System Prompt") {
chat.send(.setAsExtraPromptButtonTapped(id))
}
Divider()
Button("Delete") {
chat.send(.deleteMessageButtonTapped(id))
}
}
}
}
#Preview {
UserMessage(
id: "A",
text: #"""
Please buy me a coffee!
| Coffee | Milk |
|--------|------|
| Espresso | No |
| Latte | Yes |
```swift
func foo() {}
```
```objectivec
- (void)bar {}
```
"""#,
chat: .init(
initialState: .init(history: [], isReceivingMessage: false),
reducer: Chat(service: .init())
)
)
.padding()
.fixedSize(horizontal: /*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/, vertical: /*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
}