From 902e2b87b4cb43f6108db29299da055dcb0d81bb Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:07:29 +0800 Subject: [PATCH] fix(webui): emphasize mention brand names without shifting caret --- webui/src/components/CliAppMentionText.tsx | 11 +++++++++-- webui/src/tests/message-bubble.test.tsx | 2 +- webui/src/tests/thread-composer.test.tsx | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/webui/src/components/CliAppMentionText.tsx b/webui/src/components/CliAppMentionText.tsx index ce170b96b..dec5db890 100644 --- a/webui/src/components/CliAppMentionText.tsx +++ b/webui/src/components/CliAppMentionText.tsx @@ -21,6 +21,9 @@ export type CapabilityMentionSegment = | { kind: "mcp"; text: string; preset: McpPresetInfo } | { kind: "session"; text: string; mention: SessionMention }; +// Paint-only weight keeps the native textarea's regular-width caret and wrapping in sync. +const COMPOSER_BRAND_NAME_CLASS = "[-webkit-text-stroke:0.4px_currentColor]"; + export function cliAppInitials(app: CliAppInfo): string { const value = app.display_name || app.name; return ( @@ -237,7 +240,9 @@ function CliAppMentionToken({ ) : null} - {variant === "message" ? {mentionName} : mentionName} + + {mentionName} + ); } @@ -306,7 +311,9 @@ function McpPresetMentionToken({ ) : null} - {variant === "message" ? {mentionName} : mentionName} + + {mentionName} + ); } diff --git a/webui/src/tests/message-bubble.test.tsx b/webui/src/tests/message-bubble.test.tsx index cb4ef3dcc..39e2aa01e 100644 --- a/webui/src/tests/message-bubble.test.tsx +++ b/webui/src/tests/message-bubble.test.tsx @@ -690,7 +690,7 @@ describe("MessageBubble", () => { expect(token).toHaveAttribute("title", `${kind === "cli" ? "CLI app" : "MCP server"}: ${expected} (@${name})`); expect(token).toHaveClass("inline-flex", "items-baseline", "max-w-full", "[overflow-wrap:anywhere]"); expect(token.firstElementChild).toHaveClass("shrink-0"); - expect(token.lastElementChild).toHaveClass("min-w-0"); + expect(token.lastElementChild).toHaveClass("min-w-0", "font-semibold"); expect(message.content).toBe(`Use @${name} please`); }, ); diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsx index 3c3c7558b..5115814a2 100644 --- a/webui/src/tests/thread-composer.test.tsx +++ b/webui/src/tests/thread-composer.test.tsx @@ -2241,6 +2241,28 @@ describe("ThreadComposer", () => { expect(logo.parentElement?.className).not.toMatch(/(?:^|\s)(?:w-|m[rlx]-|p[rlx]-)/); }); + it.each(["cli", "mcp"] as const)("emphasizes the %s brand without changing composer text metrics", (kind) => { + render(); + const input = screen.getByLabelText("Message input"); + fireEvent.change(input, { target: { value: "@linear 帮我查看", selectionStart: 12 } }); + const token = screen.getByTestId(`composer-${kind}-mention-linear`); + const name = token.lastElementChild!; + expect(name).toHaveTextContent("Linear"); + expect(name).toHaveClass("[-webkit-text-stroke:0.4px_currentColor]"); + expect(token).toHaveClass("font-normal"); + expect(token.firstElementChild).not.toHaveClass("[-webkit-text-stroke:0.4px_currentColor]"); + expect(input).toHaveValue("@\u00a0Linear 帮我查看"); + expect(input).not.toHaveClass("font-semibold"); + fireEvent.compositionStart(input); + fireEvent.change(input, { target: { value: "@\u00a0Linear 帮我查看n" } }); + expect(token.lastElementChild).toBe(name); + expect(name).toHaveClass("[-webkit-text-stroke:0.4px_currentColor]"); + }); + it("uses the shared accent when an installed CLI app has no brand metadata", () => { const mention = "@obsidian-agent-cli"; const app: CliAppInfo = {