Skip to content

Commit 80f1315

Browse files
committed
added support for URL
1 parent 4dd8843 commit 80f1315

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Flitro/Editor/ContextEditorView.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,31 @@ struct UniversalDropHandler {
175175
}
176176
}
177177
handled = true
178+
} else if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) || provider.hasItemConformingToTypeIdentifier("public.url") {
179+
let typeIdentifier = provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) ? UTType.url.identifier : "public.url"
180+
provider.loadItem(forTypeIdentifier: typeIdentifier, options: nil) { item, error in
181+
if let error = error {
182+
print("Error loading URL: \(error)")
183+
return
184+
}
185+
var url: URL?
186+
if let urlObject = item as? URL {
187+
url = urlObject
188+
} else if let data = item as? Data {
189+
url = URL(dataRepresentation: data, relativeTo: nil)
190+
print("Converted data to URL: \(String(describing: url))")
191+
} else if let str = item as? String, let urlFromString = URL(string: str) {
192+
url = urlFromString
193+
}
194+
if let url = url {
195+
let browserTab = BrowserTab(title: url.absoluteString, url: url.absoluteString, browser: "default")
196+
DispatchQueue.main.async {
197+
contextManager.addItem(.browserTab(browserTab), to: contextManager.contexts[contextIndex].id)
198+
print("Added browser tab: \(browserTab.title)")
199+
}
200+
}
201+
}
202+
handled = true
178203
}
179204
}
180205
print("Drop handling complete. Handled: \(handled)")

0 commit comments

Comments
 (0)