dialogs - do not allow cancelId to point to a button that does not exist

This commit is contained in:
Benjamin Pasero 2021-08-06 14:13:29 +02:00
parent 226124eda3
commit 272d1af97f
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65

View file

@ -495,9 +495,9 @@ export class Dialog extends Disposable {
buttonMap.push({ label: button, index });
});
// macOS/linux: reverse button order
// macOS/linux: reverse button order if `cancelId` is defined
if (isMacintosh || isLinux) {
if (cancelId !== undefined) {
if (cancelId !== undefined && cancelId < buttons.length) {
const cancelButton = buttonMap.splice(cancelId, 1)[0];
buttonMap.reverse();
buttonMap.splice(buttonMap.length - 1, 0, cancelButton);