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 <noreply@anthropic.com>
This commit is contained in:
r-zakarya
2026-07-12 22:48:32 +01:00
parent bf606493bd
commit 51f72e560a
+8 -2
View File
@@ -6979,9 +6979,15 @@ function installCustomContextMenu() {
document.addEventListener('mousedown', ev => { document.addEventListener('mousedown', ev => {
if (!ev.target.closest('.custom-ctxmenu')) hide(); 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 => { 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); window.addEventListener('blur', hide);
} }