Skip to content

Commit 8c22773

Browse files
committed
Return to use the official release of markdown-ui
1 parent 8156bdd commit 8c22773

6 files changed

Lines changed: 74 additions & 46 deletions

File tree

Copilot for Xcode.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let package = Package(
3737
.package(url: "https://github.com/raspu/Highlightr", from: "2.1.0"),
3838
.package(url: "https://github.com/JohnSundell/Splash", branch: "master"),
3939
.package(url: "https://github.com/nmdias/FeedKit", from: "9.1.2"),
40-
.package(url: "https://github.com/intitni/swift-markdown-ui", branch: "main"),
40+
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.1.0"),
4141
.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.0.0"),
4242
],
4343
targets: [
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import AppKit
2+
import SwiftUI
3+
4+
struct CopyButton: View {
5+
var copy: () -> Void
6+
@State var isCopied = false
7+
var body: some View {
8+
Button(action: {
9+
withAnimation(.linear(duration: 0.1)) {
10+
isCopied = true
11+
}
12+
copy()
13+
Task {
14+
try await Task.sleep(nanoseconds: 1_000_000_000)
15+
withAnimation(.linear(duration: 0.1)) {
16+
isCopied = false
17+
}
18+
}
19+
}) {
20+
Image(systemName: isCopied ? "checkmark.circle" : "doc.on.doc")
21+
.resizable()
22+
.aspectRatio(contentMode: .fit)
23+
.frame(width: 14, height: 14)
24+
.frame(width: 20, height: 20, alignment: .center)
25+
.foregroundColor(.secondary)
26+
.background(
27+
.regularMaterial,
28+
in: RoundedRectangle(cornerRadius: 4, style: .circular)
29+
)
30+
.padding(4)
31+
}
32+
.buttonStyle(.borderless)
33+
}
34+
}

Core/Sources/SuggestionWidget/NSScrollView/CustomScrollView.swift renamed to Core/Sources/SuggestionWidget/CustomScrollView/CustomScrollView.swift

File renamed without changes.

Core/Sources/SuggestionWidget/Styles.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AppKit
2+
import MarkdownUI
23
import SwiftUI
34

45
enum Style {
@@ -53,3 +54,27 @@ extension View {
5354
)
5455
}
5556
}
57+
58+
extension MarkdownUI.Theme {
59+
static var custom: MarkdownUI.Theme {
60+
.gitHub.text {
61+
BackgroundColor(Color.clear)
62+
}
63+
.codeBlock { configuration in
64+
configuration.label
65+
.padding()
66+
.padding(.trailing)
67+
.background {
68+
RoundedRectangle(cornerRadius: 6, style: .continuous)
69+
.fill(Color(nsColor: .textBackgroundColor).opacity(0.7))
70+
}
71+
.overlay(alignment: .topTrailing) {
72+
CopyButton {
73+
NSPasteboard.general.clearContents()
74+
NSPasteboard.general.setString(configuration.content, forType: .string)
75+
}
76+
}
77+
.padding(.bottom)
78+
}
79+
}
80+
}

Core/Sources/SuggestionWidget/SuggestionPanelContent/ChatPanel.swift

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct ChatPanelMessages: View {
8080
VStack(spacing: 0) {
8181
vstack {
8282
Spacer()
83-
83+
8484
if chat.isReceivingMessage {
8585
StopRespondingButton(chat: chat)
8686
}
@@ -103,7 +103,7 @@ struct ChatPanelMessages: View {
103103
BotMessage(text: text)
104104
}
105105
}
106-
106+
107107
Spacer()
108108
}
109109
}
@@ -145,9 +145,7 @@ private struct UserMessage: View {
145145
var body: some View {
146146
Markdown(text)
147147
.textSelection(.enabled)
148-
.markdownTheme(.gitHub.text {
149-
BackgroundColor(Color.clear)
150-
})
148+
.markdownTheme(.custom)
151149
.markdownCodeSyntaxHighlighter(
152150
ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark)
153151
)
@@ -186,12 +184,10 @@ private struct BotMessage: View {
186184
NSPasteboard.general.setString(text, forType: .string)
187185
}
188186
.scaleEffect(x: -1, y: -1, anchor: .center)
189-
187+
190188
Markdown(text)
191189
.textSelection(.enabled)
192-
.markdownTheme(.gitHub.text {
193-
BackgroundColor(Color.clear)
194-
})
190+
.markdownTheme(.custom)
195191
.markdownCodeSyntaxHighlighter(
196192
ChatCodeSyntaxHighlighter(brightMode: colorScheme != .dark)
197193
)
@@ -392,38 +388,6 @@ struct GlobalChatSwitchToggleStyle: ToggleStyle {
392388
}
393389
}
394390

395-
struct CopyButton: View {
396-
var copy: () -> Void
397-
@State var isCopied = false
398-
var body: some View {
399-
Button(action: {
400-
withAnimation(.linear(duration: 0.1)) {
401-
isCopied = true
402-
}
403-
copy()
404-
Task {
405-
try await Task.sleep(nanoseconds: 1_000_000_000)
406-
withAnimation(.linear(duration: 0.1)) {
407-
isCopied = false
408-
}
409-
}
410-
}) {
411-
Image(systemName: isCopied ? "checkmark.circle" : "doc.on.doc")
412-
.resizable()
413-
.aspectRatio(contentMode: .fit)
414-
.frame(width: 14, height: 14)
415-
.frame(width: 20, height: 20, alignment: .center)
416-
.foregroundColor(.secondary)
417-
.background(
418-
.regularMaterial,
419-
in: RoundedRectangle(cornerRadius: 4, style: .circular)
420-
)
421-
.padding(4)
422-
}
423-
.buttonStyle(.borderless)
424-
}
425-
}
426-
427391
// MARK: - Previews
428392

429393
struct ChatPanel_Preview: PreviewProvider {
@@ -436,7 +400,12 @@ struct ChatPanel_Preview: PreviewProvider {
436400
.init(
437401
id: "2",
438402
isUser: false,
439-
text: "**Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?"
403+
text: """
404+
```swift
405+
func foo() {}
406+
```
407+
**Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?**Hey**! What can I do for you?
408+
"""
440409
),
441410
.init(id: "5", isUser: false, text: "Yooo"),
442411
.init(id: "4", isUser: true, text: "Yeeeehh"),

0 commit comments

Comments
 (0)