From b2d152e51f6c0ac32b559335e0d0da3c8301f0c9 Mon Sep 17 00:00:00 2001 From: Anon Ymous <73802848+ancientstraits@users.noreply.github.com> Date: Fri, 18 Jul 2025 00:45:42 +0530 Subject: [PATCH] dialog: fix default file name on Cocoa --- src/dialog/cocoa/SDL_cocoadialog.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dialog/cocoa/SDL_cocoadialog.m b/src/dialog/cocoa/SDL_cocoadialog.m index 671ca887c5..4ae894cddf 100644 --- a/src/dialog/cocoa/SDL_cocoadialog.m +++ b/src/dialog/cocoa/SDL_cocoadialog.m @@ -158,7 +158,14 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil [dialog setAllowsOtherFileTypes:YES]; if (default_location) { - [dialog setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:default_location]]]; + char last = default_location[SDL_strlen(default_location) - 1]; + NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:default_location]]; + if (last == '/') { + [dialog setDirectoryURL:url]; + } else { + [dialog setDirectoryURL:[url URLByDeletingLastPathComponent]]; + [dialog setNameFieldStringValue:[url lastPathComponent]]; + } } NSWindow *w = NULL;