Skip to content

Commit 5fb3beb

Browse files
committed
Fix DropHelper to actually handle directories
It was working with files only
1 parent 56a71ff commit 5fb3beb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

ActionUI/Helpers/DropHelper.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ struct DropModifierView<Content: SwiftUI.View>: SwiftUI.View {
9494
// • loadDataRepresentation → Data containing a UTF-8 "file://…" URL string
9595
// • loadItem → NSURL / URL object, or Data with the UTF-8 URL string
9696
// We try both paths and return whichever succeeds first.
97-
if provider.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier) {
97+
// Folders dragged from Finder conform to public.folder, not public.file-url, so check both.
98+
let fileTypeID = provider.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier)
99+
? UTType.fileURL.identifier
100+
: provider.hasItemConformingToTypeIdentifier(UTType.folder.identifier)
101+
? UTType.folder.identifier
102+
: nil
103+
if let fileTypeID {
98104
// Path 1: loadDataRepresentation (most reliable on macOS Finder drags)
99105
let viaData: String? = await withCheckedContinuation { continuation in
100-
provider.loadDataRepresentation(forTypeIdentifier: UTType.fileURL.identifier) { data, _ in
106+
provider.loadDataRepresentation(forTypeIdentifier: fileTypeID) { data, _ in
101107
guard let data else { continuation.resume(returning: nil); return }
102108
let urlString = String(data: data, encoding: .utf8)?
103109
.trimmingCharacters(in: .whitespacesAndNewlines)
@@ -108,7 +114,7 @@ struct DropModifierView<Content: SwiftUI.View>: SwiftUI.View {
108114

109115
// Path 2: loadItem (returns NSURL on some systems, Data on others)
110116
return await withCheckedContinuation { continuation in
111-
provider.loadItem(forTypeIdentifier: UTType.fileURL.identifier, options: nil) { item, _ in
117+
provider.loadItem(forTypeIdentifier: fileTypeID, options: nil) { item, _ in
112118
switch item {
113119
case let url as URL:
114120
continuation.resume(returning: url.path)

0 commit comments

Comments
 (0)