From 0b493a66c0e676f1553161bc6e63dbba0d3a9cd5 Mon Sep 17 00:00:00 2001 From: estelledc <150260202+estelledc@users.noreply.github.com> Date: Sun, 31 May 2026 11:50:45 +0800 Subject: [PATCH] fix(web): prevent caret reset on tools-menu picker mousedown (#3368) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The right-side @-button tools popover (ToolsPluginsPanel, ToolsSkillsPanel, ToolsMcpPanel) inserts text into the composer draft using the textarea's selectionStart at click time, but the picker rows had `onClick` without `onMouseDown={(e) => e.preventDefault()}`. On a real mouse, mousedown fires first, the textarea loses focus before the click handler runs, and selectionStart resets — so the inserted token lands at offset 0 instead of at the user's cursor. The @-mention popover already prevents this by calling preventDefault on mousedown for every picker row (the comment at ChatComposer.tsx:3039-3043 explains the reason). This change mirrors that protection on the three tools-menu pickers. The mention popover itself was unaffected, so design-file mentions (which only flow through the @-popover via `replaceMentionWithText`) are not impacted by this issue. The reporter's mention of "design files" appears to refer to picking a file via the @-popover, where the protection was already in place. Closes #3195 Validation: - pnpm exec vitest run tests/components/ChatComposer.tools-menu-caret.test.tsx → 3/3 passed (red on main, asserts each picker calls preventDefault on mousedown) - pnpm --filter @open-design/web test → 2501/2501 passed (260 files) - pnpm --filter @open-design/web typecheck → green - pnpm guard → green --- apps/web/src/components/ChatComposer.tsx | 13 ++ .../ChatComposer.tools-menu-caret.test.tsx | 193 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 apps/web/tests/components/ChatComposer.tools-menu-caret.test.tsx diff --git a/apps/web/src/components/ChatComposer.tsx b/apps/web/src/components/ChatComposer.tsx index 9c9686878..d63300c89 100644 --- a/apps/web/src/components/ChatComposer.tsx +++ b/apps/web/src/components/ChatComposer.tsx @@ -2658,6 +2658,11 @@ function ToolsPluginsPanel({