Skip to content

Commit 9cc4d0d

Browse files
Copilothaslinghuis
andcommitted
Refactor to use dialog close event for cleanup and promise resolution
Co-authored-by: haslinghuis <[email protected]>
1 parent aa6f589 commit 9cc4d0d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/js/gui.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,26 @@ class GuiControl {
383383

384384
const confirmAction = () => {
385385
dialog[0].close();
386-
$(document).off("keydown.informationDialog");
387-
resolve();
388386
};
389387

390388
buttonConfirm.on("click", confirmAction);
391389

392390
// Add Enter key support for single-choice dialog
393-
$(document).off("keydown.informationDialog");
394-
$(document).on("keydown.informationDialog", (e) => {
391+
const handleKeydown = (e) => {
395392
// Only trigger if Enter is pressed, dialog is open, and target is not an input/textarea
396393
if (e.which === 13 && dialog[0].open && !$(e.target).is("input, textarea")) {
397394
e.preventDefault();
398395
confirmAction();
399396
}
400-
});
397+
};
398+
399+
$(document).on("keydown.informationDialog", handleKeydown);
400+
401+
// Clean up event listener when dialog closes
402+
dialog[0].addEventListener("close", () => {
403+
$(document).off("keydown.informationDialog", handleKeydown);
404+
resolve();
405+
}, { once: true });
401406

402407
dialog[0].showModal();
403408
});

0 commit comments

Comments
 (0)