From 79554198ec8aed107653f82e2d67ca5cb6ff5705 Mon Sep 17 00:00:00 2001 From: xxiaoxiong <2482929840@qq.com> Date: Thu, 28 May 2026 22:07:18 +0800 Subject: [PATCH] fix: clear stale mention state when @ button insertion is invalid When the @ button is clicked at a position where the regex does not match (e.g., immediately after a word or on a second click after the button just inserted @), the handler now explicitly clears any existing mention state instead of leaving it intact. This prevents the popover from remaining bound to a previous cursor position, which would cause picking a file to replace the old mention location and leave the newly inserted @ behind. Mirrors the handleChange behavior which already clears mention when the regex stops matching. --- apps/web/src/components/ChatComposer.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/ChatComposer.tsx b/apps/web/src/components/ChatComposer.tsx index 2ab6de779..5cfc96702 100644 --- a/apps/web/src/components/ChatComposer.tsx +++ b/apps/web/src/components/ChatComposer.tsx @@ -774,8 +774,12 @@ export const ChatComposer = forwardRef( // does when it detects a fresh @ in the typed input. const pos = cursor + 1; const textBefore = next.slice(0, pos); - const m = /(^|\s)@([^\s@]*)$/.exec(textBefore); - if (m) setMention({ q: m[2] ?? '', cursor: pos }); + const m = /(^|\\s)@([^\\s@]*)$/.exec(textBefore); + if (m) { + setMention({ q: m[2] ?? '', cursor: pos }); + } else { + setMention(null); + } requestAnimationFrame(() => { ta.focus(); ta.setSelectionRange(pos, pos);