Browse Source

fix: Dialog does not close on ESCAPE if defaultId is set (#14196)

If defaultId is set, it was removing the key reference for the button at 0 which was previously set for the cancel_id
Keerthi Niranjan 6 years ago
parent
commit
5b48e03c7c
1 changed files with 5 additions and 5 deletions
  1. 5 5
      atom/browser/ui/message_box_mac.mm

+ 5 - 5
atom/browser/ui/message_box_mac.mm

@@ -97,11 +97,6 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
   NSArray* ns_buttons = [alert buttons];
   int button_count = static_cast<int>([ns_buttons count]);
 
-  // Bind cancel id button to escape key if there is more than one button
-  if (button_count > 1 && cancel_id >= 0 && cancel_id < button_count) {
-    [[ns_buttons objectAtIndex:cancel_id] setKeyEquivalent:@"\e"];
-  }
-
   if (default_id >= 0 && default_id < button_count) {
     // Focus the button at default_id if the user opted to do so.
     // The first button added gets set as the default selected.
@@ -110,6 +105,11 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
     [[ns_buttons objectAtIndex:default_id] setKeyEquivalent:@"\r"];
   }
 
+  // Bind cancel id button to escape key if there is more than one button
+  if (button_count > 1 && cancel_id >= 0 && cancel_id < button_count) {
+    [[ns_buttons objectAtIndex:cancel_id] setKeyEquivalent:@"\e"];
+  }
+
   if (!checkbox_label.empty()) {
     alert.showsSuppressionButton = YES;
     alert.suppressionButton.title = base::SysUTF8ToNSString(checkbox_label);