Browse Source

fix: windows save dialog extension bug (#44771)

* fix: windows save dialog extension bug

* refactor: simplify firstSpec extraction



* refactor: split when necessary



---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: nilaoda <[email protected]>
trop[bot] 5 months ago
parent
commit
f0de0348d5
1 changed files with 6 additions and 2 deletions
  1. 6 2
      shell/browser/ui/file_dialog_win.cc

+ 6 - 2
shell/browser/ui/file_dialog_win.cc

@@ -144,10 +144,14 @@ static void ApplySettings(IFileDialog* dialog, const DialogSettings& settings) {
   // We set file extension to the first none-wildcard extension to make
   // sure the dialog will update file extension automatically.
   for (size_t i = 0; i < filterspec.size(); ++i) {
-    if (std::wstring(filterspec[i].pszSpec) != L"*.*") {
+    std::wstring spec(filterspec[i].pszSpec);
+    if (spec != L"*.*") {
       // SetFileTypeIndex is regarded as one-based index.
       dialog->SetFileTypeIndex(i + 1);
-      dialog->SetDefaultExtension(filterspec[i].pszSpec);
+      // "*.jpg;*.png" => "*.jpg"
+      std::wstring first_spec = spec.substr(0, spec.find(L';'));
+      // "*.jpg" => "jpg"
+      dialog->SetDefaultExtension(first_spec.substr(2).c_str());
       break;
     }
   }