Skip to content

Commit

Permalink
🛠️ Fix copy table as JSON. Use plain button style. Display copy butto…
Browse files Browse the repository at this point in the history
…n for code block if language name is missing
  • Loading branch information
Renset committed Jun 24, 2024
1 parent ba99170 commit f5e6a53
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
50 changes: 25 additions & 25 deletions macai/UI/Chat/CodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@ struct CodeView: View {
var body: some View {
VStack {
VStack {
if lang != "" {
HStack {
HStack {
HStack {
if lang != "" {
Text(lang)
.fontWeight(.bold)
Spacer()
// Flat button to copy code to clipboard
// Display Check mark if copied
if isHovered {
Button(action: {
copyToClipboard(code?.string ?? "")
withAnimation{
isCopied = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation {
isCopied = false
}
}
Spacer()
// Flat button to copy code to clipboard
// Display Check mark if copied
if isHovered {
Button(action: {
copyToClipboard(code?.string ?? "")
withAnimation{
isCopied = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation {
isCopied = false
}
}) {
Image(systemName: isCopied ? "checkmark" : "doc.on.doc")
.frame(height: 12)
}
.buttonStyle(PlainButtonStyle())
}) {
Image(systemName: isCopied ? "checkmark" : "doc.on.doc")
.frame(height: 12)
}
.buttonStyle(PlainButtonStyle())
}
.padding(6)
}
.background(
colorScheme == .dark
? Color(NSColor(red: 30 / 255, green: 30 / 255, blue: 30 / 255, alpha: 1))
: Color(NSColor(red: 220 / 255, green: 220 / 255, blue: 220 / 255, alpha: 1))
)
.padding(6)
}
.background(
colorScheme == .dark
? Color(NSColor(red: 30 / 255, green: 30 / 255, blue: 30 / 255, alpha: 1))
: Color(NSColor(red: 220 / 255, green: 220 / 255, blue: 220 / 255, alpha: 1))
)

AttributedText(code ?? NSAttributedString(string: ""))
.textSelection(.enabled)
Expand Down
33 changes: 29 additions & 4 deletions macai/UI/Chat/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct TableRowView: View {
struct TableView: View {
let header: [String]
let tableData: [[String]]
@State private var isCopied = false
@State private var isCopiedJSON = false

private func copyTableToClipboard() {
let headerString = header.joined(separator: "\t")
Expand Down Expand Up @@ -98,17 +100,40 @@ struct TableView: View {
VStack {
HStack {
Spacer()
Button(action: copyTableToClipboard) {
Button(action: {
copyTableAsJSONToClipboard()
withAnimation{
isCopiedJSON = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation {
isCopiedJSON = false
}
}
}) {
Image(systemName: isCopiedJSON ? "checkmark" : "doc.on.doc")
Text("JSON")
Image(systemName: "doc.on.doc")
}
.padding(0)
.padding(.trailing, 16)
.buttonStyle(PlainButtonStyle())


Button(action: copyTableToClipboard) {
Image(systemName: "doc.on.doc")
Button(action: {
copyTableToClipboard()
withAnimation{
isCopied = true
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
withAnimation {
isCopied = false
}
}
}) {
Image(systemName: isCopied ? "checkmark" : "doc.on.doc")
}
.padding(0)
.buttonStyle(PlainButtonStyle())
}
.padding(.bottom, 2)
VStack(spacing: 0) {
Expand Down

0 comments on commit f5e6a53

Please sign in to comment.