From 36a6a713b4f673c9129935b268268b83c0cb2492 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 23 Dec 2020 18:01:02 +0200 Subject: [PATCH] [3.2] Fix file drag-drop on M1 Macs. --- platform/osx/os_osx.mm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index ae7ace16671..63d98673af3 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -638,26 +638,30 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (BOOL)performDragOperation:(id)sender { - NSPasteboard *pboard = [sender draggingPasteboard]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 - NSArray *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL]; -#else - NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; -#endif - Vector files; - for (NSUInteger i = 0; i < filenames.count; i++) { + NSPasteboard *pboard = [sender draggingPasteboard]; + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 - NSString *ns = [[filenames objectAtIndex:i] path]; -#else - NSString *ns = [filenames objectAtIndex:i]; -#endif + NSArray *items = pboard.pasteboardItems; + for (NSPasteboardItem *item in items) { + NSString *path = [item stringForType:NSPasteboardTypeFileURL]; + NSString *ns = [NSURL URLWithString:path].path; char *utfs = strdup([ns UTF8String]); String ret; ret.parse_utf8(utfs); free(utfs); files.push_back(ret); } +#else + NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; + for (NSString *ns in filenames) { + char *utfs = strdup([ns UTF8String]); + String ret; + ret.parse_utf8(utfs); + free(utfs); + files.push_back(ret); + } +#endif if (files.size()) { OS_OSX::singleton->main_loop->drop_files(files, 0);