updates plug with all sorts of awesome improvements

This commit is contained in:
2026-11-09 13:09:09 +01:00
parent a92d6f8871
commit 3afdb6d67f
553 changed files with 22780 additions and 13155 deletions
+6 -1
View File
@@ -15,7 +15,7 @@ public enum PasteKind: Sendable, Equatable {
self = .object(.json, text.contains("\n") ? text : JSONFormatter.pretty(text))
} else if Self.isXML(text) {
self = .object(.xml, text)
} else if let csv = Self.csvText(pasted), CSVTable.detect(csv) != nil {
} else if let csv = Self.csvText(pasted), let table = CSVTable.detect(csv), !Self.hasBraces(table) {
self = .object(.csv, csv)
} else {
self = .text
@@ -30,6 +30,11 @@ public enum PasteKind: Sendable, Equatable {
return lines.isEmpty ? nil : lines.joined(separator: "\n")
}
/// Config and CSS split evenly on `;` too; a brace in a field means code, not data.
private static func hasBraces(_ table: CSVTable) -> Bool {
table.rows.contains { row in row.contains { $0.contains("{") || $0.contains("}") } }
}
private static func isJSON(_ text: String) -> Bool {
guard text.hasPrefix("{") || text.hasPrefix("[") else { return false }
return (try? JSONSerialization.jsonObject(with: Data(text.utf8))) != nil
+20
View File
@@ -0,0 +1,20 @@
import Foundation
/// What a `plak://` URL from another app asks for: append its text, or append the pasteboard.
public enum URLCommand: Equatable, Sendable {
case append(String)
case paste
/// Reads `plak://append?text=…` and `plak://paste`; any other URL gives nil.
public init?(_ url: URL) {
guard url.scheme?.lowercased() == "plak", let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil }
switch components.host?.lowercased() {
case "append":
self = .append(components.queryItems?.first { $0.name == "text" }?.value ?? "")
case "paste":
self = .paste
default:
return nil
}
}
}