Skip to content

🐛 Fix duplicate file extension when saving on macOS#595

Open
NielsBillen wants to merge 1 commit into
vinceglb:mainfrom
NielsBillen:fix/macos-duplicate-save-extension
Open

🐛 Fix duplicate file extension when saving on macOS#595
NielsBillen wants to merge 1 commit into
vinceglb:mainfrom
NielsBillen:fix/macos-duplicate-save-extension

Conversation

@NielsBillen

Copy link
Copy Markdown

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

NSSavePanel automatically appends the extension 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.

Windows is unaffected because its native IFileSaveDialog.SetDefaultExtension only 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 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.

Tests

Added unit tests for buildFileSaverAllowedFileTypes in FileSaverNameTest (commonTest). :filekit-dialogs:jvmTest passes locally.

Note: macosMain was not compiled locally (no macOS host available); the change is symmetric to the JVM path. A macOS CI run would be worth confirming.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants