🐛 Fix duplicate file extension when saving on macOS#595
Open
NielsBillen wants to merge 1 commit into
Open
Conversation
On macOS, NSSavePanel automatically appends the extension taken from allowedFileTypes to the entered file name. The save dialog also baked the extension into nameFieldStringValue via buildFileSaverSuggestedName, so the panel appended it a second time and produced names like "name.ext.ext". Windows is unaffected because its native dialog only appends a default extension when the name has none. Mirror the Windows behaviour on both macOS code paths (native macosMain and the JVM JNA picker): set the bare suggestedName as the name field and let allowedFileTypes supply the extension. A new shared buildFileSaverAllowedFileTypes helper orders the file types with the default extension first, so NSSavePanel appends the default one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS the file extension is added twice when saving a file (e.g.
report.pdf.pdf). The issue is not present on Windows.Root cause
NSSavePanelautomatically appends the extension fromallowedFileTypesto the entered file name. The save dialog also baked the extension intonameFieldStringValueviabuildFileSaverSuggestedName, so the panel appended it a second time.Windows is unaffected because its native
IFileSaveDialog.SetDefaultExtensiononly appends an extension when the file name has none — it sets a bare name plus a separate default extension.Fix
Mirror the Windows approach on both macOS code paths:
macosMain/.../FileKit.macos.kt(native macOS target)jvmMain/.../platform/mac/MacOSFilePicker.kt(JVM / Desktop)Set the bare
suggestedNameas the name field and letallowedFileTypessupply the extension. A new sharedbuildFileSaverAllowedFileTypeshelper orders the file types with the default extension first, soNSSavePanelappends the default one.Tests
Added unit tests for
buildFileSaverAllowedFileTypesinFileSaverNameTest(commonTest).:filekit-dialogs:jvmTestpasses locally.