fix: crash when dialog.showMessageBoxSync with missing buttons (#40996)

* fix: crash when dialog.showMessageBoxSync missing buttons

* chore: feedback from review
This commit is contained in:
Shelley Vohr 2024-01-18 13:21:15 +01:00 committed by GitHub
parent df7f07a8af
commit 7e6fb97a2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 8 deletions

View file

@ -76,15 +76,16 @@ NSAlert* CreateNSAlert(const MessageBoxSettings& settings) {
[[ns_buttons objectAtIndex:settings.default_id] setKeyEquivalent:@"\r"];
}
// Bind cancel id button to escape key if there is more than one button
if (button_count > 1 && settings.cancel_id >= 0 &&
settings.cancel_id < button_count) {
[[ns_buttons objectAtIndex:settings.cancel_id] setKeyEquivalent:@"\e"];
}
if (button_count > 1 && settings.cancel_id >= 0) {
// Bind cancel id button to escape key if there is more than one button.
if (settings.cancel_id < button_count) {
[[ns_buttons objectAtIndex:settings.cancel_id] setKeyEquivalent:@"\e"];
}
// TODO(@codebytere): This behavior violates HIG & should be deprecated.
if (settings.cancel_id >= 0 && settings.cancel_id == settings.default_id) {
[[ns_buttons objectAtIndex:settings.default_id] highlight:YES];
// TODO(@codebytere): This behavior violates HIG & should be deprecated.
if (settings.cancel_id == settings.default_id) {
[[ns_buttons objectAtIndex:settings.default_id] highlight:YES];
}
}
if (!settings.checkbox_label.empty()) {