From 52bf8fb8d0520059e3073d2f9151f815148e6cb2 Mon Sep 17 00:00:00 2001 From: "Stiliyan Tonev (Bark)" Date: Thu, 26 Jun 2025 09:00:58 +0300 Subject: [PATCH] WebUI: Close modals in the same order as opening --- src/webui/www/private/scripts/client.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 082b55726..db1637a73 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1774,14 +1774,21 @@ window.addEventListener("DOMContentLoaded", (event) => { deleteSelectedTorrentsFN(event.shiftKey); break; - case "Escape": + case "Escape": { if (event.target.isContentEditable) return; event.preventDefault(); - Object.values(MochaUI.Windows.instances).forEach((modal) => { - modal.close(); + const modalInstances = Object.values(MochaUI.Windows.instances); + if (modalInstances.length <= 0) + return; + // MochaUI.currentModal does not update after a modal is closed + // use `timestamp` for sequential closing + const latestModal = modalInstances.reduce((prev, curr) => { + return (prev.timestamp > curr.timestamp) ? prev : curr; }); + latestModal.close(); break; + } } });