From 51f72e560a7ad19d807202e3b8a204ce741e54e6 Mon Sep 17 00:00:00 2001 From: r-zakarya <82443831+r-zakarya@users.noreply.github.com> Date: Sun, 12 Jul 2026 22:48:32 +0100 Subject: [PATCH] fix(ctxmenu): Esc with the context menu open closes only the menu Same Esc fall-through class: the menu's Esc handler was bubble-phase and didn't stop the keystroke, so the slideover capture handler fired first and popped the discard prompt while the menu also hid. Capture + stopPropagation, gated on the menu being visible; registered before the slideover handler (installCustomContextMenu runs at the top of init) so ordering is guaranteed. Co-Authored-By: Claude Opus 4.8 --- js/app.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/app.js b/js/app.js index a17d1c9..a18b30f 100644 --- a/js/app.js +++ b/js/app.js @@ -6979,9 +6979,15 @@ function installCustomContextMenu() { document.addEventListener('mousedown', ev => { if (!ev.target.closest('.custom-ctxmenu')) hide(); }); + // Capture + stopPropagation: Esc with the menu open must close ONLY the + // menu — otherwise the same keystroke reaches the slideover/fallback + // handlers and also closes (or discard-prompts) whatever is behind. document.addEventListener('keydown', ev => { - if (ev.key === 'Escape') hide(); - }); + if (ev.key !== 'Escape') return; + if (menu.classList.contains('is-hidden')) return; + ev.stopPropagation(); + hide(); + }, true); window.addEventListener('blur', hide); }