Skip to content

Commit

Permalink
Support paste operation for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
varkrishna committed Sep 21, 2024
1 parent 9e3b928 commit 1e787f8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/JSONViewer/JSONNodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,23 @@ public struct JSONNodeView: View {
}
.contextMenu(menuItems: {
Button {
#if os(macOS)
NSPasteboard.general.clearContents()
if !node.isExpandable {
NSPasteboard.general.setString("{\"\(node.key)\": \"\(node.value)\"}", forType: .string)
NSPasteboard.general.setString("{\"\(node.key)\": \"\(node.value ?? "")\"}", forType: .string)
} else {
let jsonString = node.jsonString()
NSPasteboard.general.setString(jsonString, forType: .string)
}
#elseif os(iOS)
UIPasteboard.general.string = nil
if !node.isExpandable {
UIPasteboard.general.string = "{\"\(node.key)\": \"\(node.value ?? "")\"}"
} else {
let jsonString = node.jsonString()
UIPasteboard.general.string = jsonString
}
#endif
} label: {
Text("Copy")
}
Expand Down

0 comments on commit 1e787f8

Please sign in to comment.