From 32df5546b40b82a487f4e100eeb82b97c9e08b09 Mon Sep 17 00:00:00 2001 From: humayunak Date: Sun, 24 May 2026 07:53:13 +0500 Subject: [PATCH] fix(webui): prevent approval and clarify cards stealing focus from composer textarea When tool approval or clarification cards appear during streaming, they unconditionally call focus() on their input elements via setTimeout, stealing focus from the composer (#msg) if the user is actively typing. This silently drops keystrokes mid-type. Add a guard: only move focus to the card if the composer textarea does not already have focus. The document.activeElement check matches the pattern already used upstream in other focus-sensitive components. Fixes: # --- static/messages.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/static/messages.js b/static/messages.js index 170952dd..29c8ae40 100644 --- a/static/messages.js +++ b/static/messages.js @@ -2428,7 +2428,9 @@ function showApprovalCard(pending, pendingCount) { card.classList.add("visible"); if (typeof applyLocaleToDOM === "function") applyLocaleToDOM(); const onceBtn = $("approvalBtnOnce"); - if (onceBtn) setTimeout(() => onceBtn.focus({preventScroll: true}), 50); + if (onceBtn && document.activeElement !== $('msg')) { + setTimeout(() => onceBtn.focus({preventScroll: true}), 50); + } } async function respondApproval(choice) { @@ -2864,7 +2866,11 @@ function showClarifyCard(pending) { card.classList.add("visible"); _syncClarifyCollapseButton(card); if (typeof applyLocaleToDOM === "function") applyLocaleToDOM(); - if (input && !sameClarify) setTimeout(() => input.focus({preventScroll: true}), 50); + // Move focus to clarify input synchronously (not in setTimeout) and + // only if the user wasn't mid-type in the composer textarea. + if (input && !sameClarify && document.activeElement !== $('msg')) { + input.focus({preventScroll: true}); + } } async function respondClarify(response) {