From 8f696064d5f600779818fefb9585b61054d2e27c Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Sat, 13 Jun 2026 07:15:44 +0900 Subject: [PATCH] AI reply menu: outside-click closer ignores clicks inside the menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The document-level capture listener was closing the popover on ANY click — including clicks inside the context textarea, which made it impossible to focus the input. Replaced with an inline handler that bails when the click target is inside the menu. --- static/js/emailLibrary.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/static/js/emailLibrary.js b/static/js/emailLibrary.js index 8a0826e0a..cec7f8983 100644 --- a/static/js/emailLibrary.js +++ b/static/js/emailLibrary.js @@ -5971,7 +5971,15 @@ function _showAiReplyChoice(btn, em, data) { // textarea stays focused. menu.addEventListener('mousedown', (ev) => ev.stopPropagation()); document.body.appendChild(menu); - setTimeout(() => document.addEventListener('click', _closeAiReplyChoice, true), 0); + // Outside-click closer: only fires when the click target is OUTSIDE + // the menu. The original handler closed on any click which made + // focusing the textarea immediately dismiss the popover. + const outsideClose = (ev) => { + if (menu.contains(ev.target)) return; + document.removeEventListener('click', outsideClose, true); + _closeAiReplyChoice(); + }; + setTimeout(() => document.addEventListener('click', outsideClose, true), 0); } function _handleAiReplyButton(ev, em, data) {