fix(webui): unify skill and session link highlighting (#6454)
* fix(webui): refine skill reference highlighting * fix(webui): highlight composer skills and align session links
This commit is contained in:
1 parent
d14c54c31c
commit
424d2debc2
12 files changed
+305
-91
No files matched your search
@@ -23,6 +23,7 @@ import { NewChatSkeletonFixture } from "./new-chat-skeleton-fixture";
|
||||
import "../src/globals.css";
|
||||
import { DiagramFixture } from "./diagram-fixture";
|
||||
import { TypographyFixture } from "./typography-fixture";
|
||||
import { InlineReferencesFixture } from "./inline-references-fixture";
|
||||
import { MarkdownEmphasisFixture } from "./markdown-emphasis-fixture";
|
||||
import { HistoryBoundaryFixture } from "./history-boundary-fixture";
|
||||
import { ChatFailureFixture } from "./chat-failure-fixture";
|
||||
@@ -244,6 +245,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
? <MarkdownEmphasisFixture />
|
||||
: parameters.get("case") === "typography"
|
||||
? <ClientProvider client={railClient} token="fixture"><TypographyFixture /></ClientProvider>
|
||||
: parameters.get("case") === "inline-references"
|
||||
? <ClientProvider client={railClient} token="fixture"><InlineReferencesFixture /></ClientProvider>
|
||||
: parameters.get("case") === "idle-compaction"
|
||||
? <IdleCompactionFixture />
|
||||
: parameters.get("case") === "history-hydration"
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ThemeProvider, useTheme } from "@/hooks/useTheme";
|
||||
import { useReadingTypography } from "@/hooks/useReadingTypography";
|
||||
import type { ChatSummary, UIMessage } from "@/lib/types";
|
||||
|
||||
const session: ChatSummary = {
|
||||
key: "websocket:typography", channel: "websocket", chatId: "typography",
|
||||
createdAt: null, updatedAt: null, title: "Reference target", preview: "",
|
||||
handle: { id: "handle_12345678901234567890123456789012", name: "typography" },
|
||||
};
|
||||
const answer: UIMessage = {
|
||||
id: "reference-answer", role: "assistant", createdAt: 1,
|
||||
content: "[相关会话](#session/websocket%3Atypography) · [外部文档](https://example.com/reference)",
|
||||
};
|
||||
|
||||
export function InlineReferencesFixture() {
|
||||
useReadingTypography();
|
||||
const { theme } = useTheme();
|
||||
const [sent, setSent] = useState<UIMessage[]>([]);
|
||||
return <ThemeProvider theme={theme}>
|
||||
<main className="mx-auto h-full max-w-[var(--content-column-width)] space-y-6 overflow-y-auto p-4">
|
||||
{[answer, ...sent].map(message => <MessageBubble key={message.id} message={message} />)}
|
||||
<ThreadComposer compactWhenIdle sessions={[session]} modelLabel="Fixture" persistDraft={false}
|
||||
onSend={text => setSent(current => [...current, {
|
||||
id: `sent-${current.length}`, role: "user", content: text, createdAt: current.length + 2,
|
||||
}])} />
|
||||
</main>
|
||||
</ThemeProvider>;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { expect, test, type Locator } from "@playwright/test";
|
||||
|
||||
async function expectMatchingInputLayers(input: Locator) {
|
||||
const metrics = await input.evaluate((node: HTMLTextAreaElement) => {
|
||||
const overlay = node.previousElementSibling as HTMLElement;
|
||||
const readStyle = (element: Element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
fontFamily: style.fontFamily, fontSize: style.fontSize, fontWeight: style.fontWeight,
|
||||
lineHeight: style.lineHeight, letterSpacing: style.letterSpacing,
|
||||
padding: style.padding, autospace: style.getPropertyValue("text-autospace"),
|
||||
};
|
||||
};
|
||||
const glyphs = (element: Element) => {
|
||||
const origin = element.getBoundingClientRect();
|
||||
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
||||
const result: number[][] = [];
|
||||
while (walker.nextNode()) {
|
||||
const text = walker.currentNode;
|
||||
for (let index = 0; index < (text.textContent?.length ?? 0); index++) {
|
||||
const range = document.createRange();
|
||||
range.setStart(text, index);
|
||||
range.setEnd(text, index + 1);
|
||||
const rect = range.getBoundingClientRect();
|
||||
result.push([rect.x - origin.x, rect.y - origin.y, rect.width, rect.height]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const plain = overlay.cloneNode(false) as HTMLElement;
|
||||
plain.style.visibility = "hidden";
|
||||
plain.textContent = overlay.textContent;
|
||||
overlay.parentElement!.append(plain);
|
||||
plain.scrollTop = overlay.scrollTop;
|
||||
try {
|
||||
return {
|
||||
inputStyle: readStyle(node), overlayStyle: readStyle(overlay),
|
||||
overlayText: overlay.textContent, value: node.value,
|
||||
decoratedGlyphs: glyphs(overlay), plainGlyphs: glyphs(plain),
|
||||
};
|
||||
} finally {
|
||||
plain.remove();
|
||||
}
|
||||
});
|
||||
expect(metrics.overlayStyle).toEqual(metrics.inputStyle);
|
||||
expect(metrics.overlayText).toBe(metrics.value);
|
||||
expect(metrics.decoratedGlyphs.length).toBe(metrics.plainGlyphs.length);
|
||||
for (let index = 0; index < metrics.plainGlyphs.length; index++) {
|
||||
for (let dimension = 0; dimension < 4; dimension++) {
|
||||
expect(Math.abs(metrics.decoratedGlyphs[index][dimension] - metrics.plainGlyphs[index][dimension])).toBeLessThanOrEqual(0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const narrow of [false, true]) {
|
||||
for (const theme of ["light", "dark"]) {
|
||||
test(`inline references preserve native editing: ${narrow ? "narrow" : "desktop"}, ${theme}`, async ({ page }, info) => {
|
||||
await page.setViewportSize(narrow ? { width: 390, height: 844 } : { width: 1440, height: 1000 });
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await page.addInitScript(theme => {
|
||||
localStorage.setItem("nanobot.locale", "en");
|
||||
localStorage.setItem("nanobot-webui.theme", theme);
|
||||
}, theme);
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.goto("/browser/fixture.html?case=inline-references");
|
||||
|
||||
const sessionLink = page.getByRole("link", { name: "相关会话", exact: true });
|
||||
await sessionLink.waitFor({ state: "visible", timeout: 15_000 });
|
||||
await expect(sessionLink).toHaveAttribute("href", "#/chat/websocket%3Atypography");
|
||||
await expect(sessionLink.locator("span")).toHaveCSS("color", "rgb(244, 169, 73)");
|
||||
await sessionLink.click();
|
||||
await expect(page).toHaveURL(/#\/chat\/websocket%3Atypography$/);
|
||||
const externalLink = page.getByRole("link", { name: "外部文档", exact: true });
|
||||
await expect(externalLink).toHaveAttribute("href", "https://example.com/reference");
|
||||
await expect(externalLink).toHaveAttribute("target", "_blank");
|
||||
await expect(externalLink).toHaveCSS("color", theme === "light" ? "rgb(59, 130, 246)" : "rgb(147, 197, 253)");
|
||||
|
||||
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
||||
const overlay = page.locator(".thread-composer-input > div[aria-hidden]");
|
||||
const text = "like $workflow 和 $skill-creator,检查中文 English 与换行。";
|
||||
await input.focus();
|
||||
await input.pressSequentially(text);
|
||||
const skill = page.getByTestId("composer-skill-reference-workflow");
|
||||
await expect(skill).toHaveText("$workflow");
|
||||
await expect(skill).toHaveCSS("color", "rgb(244, 169, 73)");
|
||||
await expect(skill).toHaveCSS("font-weight", "400");
|
||||
expect(await skill.getAttribute("title")).toBeNull();
|
||||
await expectMatchingInputLayers(input);
|
||||
|
||||
const start = text.indexOf("workflow") + 1;
|
||||
const end = start + 4;
|
||||
await input.evaluate((node: HTMLTextAreaElement, range) => node.setSelectionRange(range.start, range.end), { start, end });
|
||||
await input.press("ControlOrMeta+c");
|
||||
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(text.slice(start, end));
|
||||
await input.press("ControlOrMeta+x");
|
||||
await expect(input).toHaveValue(text.slice(0, start) + text.slice(end));
|
||||
await input.press("ControlOrMeta+z");
|
||||
await expect(input).toHaveValue(text);
|
||||
expect(await input.evaluate((node: HTMLTextAreaElement) => [node.selectionStart, node.selectionEnd])).toEqual([start, end]);
|
||||
|
||||
const mixed = "粘贴 $workflow 与 @typography,继续输入。";
|
||||
await input.fill("");
|
||||
await page.evaluate(text => navigator.clipboard.writeText(text), mixed);
|
||||
await input.press("ControlOrMeta+v");
|
||||
await expect(input).toHaveValue(mixed);
|
||||
await expect(skill).toHaveText("$workflow");
|
||||
await expect(page.getByTestId("composer-session-mention-typography")).toHaveText("@typography");
|
||||
await expect(overlay).toHaveText(mixed);
|
||||
|
||||
const multiline = Array.from({ length: 18 }, (_, index) => `第 ${index + 1} 行 $workflow 中文 English 光标与装饰层保持一致。`).join("\n");
|
||||
await input.fill(multiline);
|
||||
await input.press("ControlOrMeta+End");
|
||||
await expect.poll(async () => Math.abs(await input.evaluate(node => node.scrollTop) - await overlay.evaluate(node => node.scrollTop))).toBeLessThanOrEqual(1);
|
||||
await expectMatchingInputLayers(input);
|
||||
await input.fill(text);
|
||||
await input.press("End");
|
||||
await page.screenshot({ path: info.outputPath("composer-skills.png") });
|
||||
await page.getByRole("button", { name: "Send message", exact: true }).click();
|
||||
await expect(page.getByTestId("message-skill-reference-workflow")).toHaveText("$workflow");
|
||||
await expect(page.getByTestId("message-skill-reference-workflow")).toHaveCSS("color", "rgb(244, 169, 73)");
|
||||
await expect(page.locator("[data-user-text-bubble]").last().locator("p")).toHaveText(text);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { ReactNode } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const INLINE_TOKEN_HIGHLIGHT_COLOR = "var(--inline-token-highlight)";
|
||||
export const INLINE_REFERENCE_HIGHLIGHT_COLOR = "var(--inline-reference-highlight)";
|
||||
|
||||
export function InlineTokenHighlight({
|
||||
children,
|
||||
|
||||
@@ -24,7 +24,7 @@ import { MarkdownCodeBlock } from "@/components/markdown-diagrams/MarkdownCodeBl
|
||||
import { MarkdownCodeContext } from "@/components/markdown-diagrams/context";
|
||||
import { WebLink } from "@/components/WebLink";
|
||||
import {
|
||||
INLINE_TOKEN_HIGHLIGHT_COLOR,
|
||||
INLINE_REFERENCE_HIGHLIGHT_COLOR,
|
||||
InlineTokenHighlight,
|
||||
} from "@/components/InlineTokenHighlight";
|
||||
import {
|
||||
@@ -629,9 +629,9 @@ export default function MarkdownTextRenderer({
|
||||
<a
|
||||
href={sessionHref}
|
||||
className="rounded-sm underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60"
|
||||
style={{ textDecorationColor: INLINE_TOKEN_HIGHLIGHT_COLOR }}
|
||||
style={{ textDecorationColor: INLINE_REFERENCE_HIGHLIGHT_COLOR }}
|
||||
>
|
||||
<InlineTokenHighlight color={INLINE_TOKEN_HIGHLIGHT_COLOR}>
|
||||
<InlineTokenHighlight color={INLINE_REFERENCE_HIGHLIGHT_COLOR}>
|
||||
{markdownChildren}
|
||||
</InlineTokenHighlight>
|
||||
</a>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
INLINE_REFERENCE_HIGHLIGHT_COLOR,
|
||||
InlineTokenHighlight,
|
||||
} from "@/components/InlineTokenHighlight";
|
||||
import type { CapabilityMentionSegment } from "@/lib/composer-mention-text";
|
||||
|
||||
export type InlineReferenceSegment =
|
||||
| CapabilityMentionSegment
|
||||
| { kind: "skill"; text: string; name: string };
|
||||
|
||||
export function withSkillReferences(segments: CapabilityMentionSegment[]): InlineReferenceSegment[] {
|
||||
const result: InlineReferenceSegment[] = [];
|
||||
for (const segment of segments) {
|
||||
if (segment.kind !== "text") {
|
||||
result.push(segment);
|
||||
continue;
|
||||
}
|
||||
let cursor = 0;
|
||||
for (const match of segment.text.matchAll(/\$([A-Za-z0-9_-]+)/g)) {
|
||||
if (match.index > cursor) {
|
||||
result.push({ kind: "text", text: segment.text.slice(cursor, match.index) });
|
||||
}
|
||||
result.push({ kind: "skill", text: match[0], name: match[0].slice(1) });
|
||||
cursor = match.index + match[0].length;
|
||||
}
|
||||
if (cursor < segment.text.length) {
|
||||
result.push({ kind: "text", text: segment.text.slice(cursor) });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function SkillReferenceToken({ name, testId }: { name: string; testId: string }) {
|
||||
return (
|
||||
<InlineTokenHighlight
|
||||
testId={testId}
|
||||
className="font-normal"
|
||||
color={INLINE_REFERENCE_HIGHLIGHT_COLOR}
|
||||
>
|
||||
<span className="opacity-90">$</span>{name}
|
||||
</InlineTokenHighlight>
|
||||
);
|
||||
}
|
||||
@@ -1,70 +1,11 @@
|
||||
import { Fragment } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
CapabilityMentionToken,
|
||||
splitCapabilityMentionSegments,
|
||||
} from "@/components/CliAppMentionText";
|
||||
import {
|
||||
INLINE_TOKEN_HIGHLIGHT_COLOR,
|
||||
InlineTokenHighlight,
|
||||
} from "@/components/InlineTokenHighlight";
|
||||
import { SkillReferenceToken, withSkillReferences } from "@/components/SkillReferenceText";
|
||||
import type { CliAppInfo, McpPresetInfo, SessionMention } from "@/lib/types";
|
||||
import type { CapabilityMentionSegment } from "@/lib/composer-mention-text";
|
||||
|
||||
type SkillReferenceSegment =
|
||||
| { kind: "text"; text: string }
|
||||
| { kind: "skill"; text: string; name: string };
|
||||
|
||||
type UserMessageSegment =
|
||||
| CapabilityMentionSegment
|
||||
| { kind: "skill"; text: string; name: string };
|
||||
|
||||
function splitSkillReferenceSegments(value: string): SkillReferenceSegment[] {
|
||||
if (!value) return [];
|
||||
const segments: SkillReferenceSegment[] = [];
|
||||
const referenceRe = /\$([A-Za-z0-9_-]+)/g;
|
||||
let cursor = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = referenceRe.exec(value)) !== null) {
|
||||
const name = match[1] ?? "";
|
||||
if (match.index > cursor) {
|
||||
segments.push({ kind: "text", text: value.slice(cursor, match.index) });
|
||||
}
|
||||
segments.push({
|
||||
kind: "skill",
|
||||
text: value.slice(match.index, referenceRe.lastIndex),
|
||||
name,
|
||||
});
|
||||
cursor = referenceRe.lastIndex;
|
||||
}
|
||||
if (cursor < value.length) {
|
||||
segments.push({ kind: "text", text: value.slice(cursor) });
|
||||
}
|
||||
return segments.length ? segments : [{ kind: "text", text: value }];
|
||||
}
|
||||
|
||||
function splitUserMessageSegments(
|
||||
value: string,
|
||||
cliApps: CliAppInfo[],
|
||||
mcpPresets: McpPresetInfo[],
|
||||
sessionMentions: SessionMention[],
|
||||
): UserMessageSegment[] {
|
||||
const segments: UserMessageSegment[] = [];
|
||||
for (const segment of splitCapabilityMentionSegments(
|
||||
value,
|
||||
cliApps,
|
||||
mcpPresets,
|
||||
sessionMentions,
|
||||
)) {
|
||||
if (segment.kind === "text") {
|
||||
segments.push(...splitSkillReferenceSegments(segment.text));
|
||||
} else {
|
||||
segments.push(segment);
|
||||
}
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function UserMessageText({
|
||||
text,
|
||||
@@ -77,8 +18,9 @@ export function UserMessageText({
|
||||
mcpPresets: McpPresetInfo[];
|
||||
sessionMentions?: SessionMention[];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const segments = splitUserMessageSegments(text, cliApps, mcpPresets, sessionMentions);
|
||||
const segments = withSkillReferences(
|
||||
splitCapabilityMentionSegments(text, cliApps, mcpPresets, sessionMentions),
|
||||
);
|
||||
return (
|
||||
<>
|
||||
{segments.map((segment, index) => {
|
||||
@@ -86,14 +28,11 @@ export function UserMessageText({
|
||||
return <Fragment key={`text-${index}`}>{segment.text}</Fragment>;
|
||||
}
|
||||
if (segment.kind === "skill") return (
|
||||
<InlineTokenHighlight
|
||||
<SkillReferenceToken
|
||||
key={`skill-${segment.name}-${index}`}
|
||||
name={segment.name}
|
||||
testId={`message-skill-reference-${segment.name.toLowerCase()}`}
|
||||
title={t("message.skill", { name: segment.name })}
|
||||
color={INLINE_TOKEN_HIGHLIGHT_COLOR}
|
||||
>
|
||||
{segment.text}
|
||||
</InlineTokenHighlight>
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<CapabilityMentionToken
|
||||
|
||||
@@ -45,10 +45,14 @@ import {
|
||||
mcpPresetInitials,
|
||||
splitCapabilityMentionSegments,
|
||||
} from "@/components/CliAppMentionText";
|
||||
import {
|
||||
SkillReferenceToken,
|
||||
withSkillReferences,
|
||||
type InlineReferenceSegment,
|
||||
} from "@/components/SkillReferenceText";
|
||||
import {
|
||||
composerMentionText,
|
||||
isCapabilityMentionStart,
|
||||
type CapabilityMentionSegment,
|
||||
} from "@/lib/composer-mention-text";
|
||||
import { INLINE_TOKEN_HIGHLIGHT_COLOR } from "@/components/InlineTokenHighlight";
|
||||
import {
|
||||
@@ -1715,9 +1719,11 @@ export function ThreadComposer({
|
||||
|
||||
const showCliAppMenu = filteredMentionCandidates.length > 0;
|
||||
const showAnyPalette = showSlashMenu || showCliAppMenu;
|
||||
const hasMentionDecorations = displayMentionSegments.some(
|
||||
(segment) => segment.kind !== "text",
|
||||
const inlineSegments = useMemo(
|
||||
() => withSkillReferences(displayMentionSegments),
|
||||
[displayMentionSegments],
|
||||
);
|
||||
const hasInlineDecorations = inlineSegments.some((segment) => segment.kind !== "text");
|
||||
const activeCliMentionApps = useMemo(() => {
|
||||
const seen = new Set<string>();
|
||||
return mentionSegments.flatMap((segment) => {
|
||||
@@ -2705,10 +2711,10 @@ export function ThreadComposer({
|
||||
) : null}
|
||||
<GoalStateStrip goalState={goalState} />
|
||||
<div className="thread-composer-input relative min-w-0">
|
||||
{hasMentionDecorations ? (
|
||||
<ComposerCliMentionOverlay
|
||||
{hasInlineDecorations ? (
|
||||
<ComposerInlineReferenceOverlay
|
||||
overlayRef={mentionOverlayRef}
|
||||
segments={displayMentionSegments}
|
||||
segments={inlineSegments}
|
||||
isHero={isHero}
|
||||
isComposing={mentionInput.isComposing}
|
||||
className={inputTextClasses}
|
||||
@@ -2746,7 +2752,7 @@ export function ThreadComposer({
|
||||
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
|
||||
"focus:outline-none focus-visible:outline-none",
|
||||
"disabled:cursor-not-allowed",
|
||||
hasMentionDecorations && "text-transparent selection:bg-primary/20",
|
||||
hasInlineDecorations && "text-transparent selection:bg-primary/20",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
@@ -2989,7 +2995,7 @@ function QueuedPromptPreview({
|
||||
);
|
||||
}
|
||||
|
||||
function ComposerCliMentionOverlay({
|
||||
function ComposerInlineReferenceOverlay({
|
||||
overlayRef,
|
||||
segments,
|
||||
isHero,
|
||||
@@ -2998,7 +3004,7 @@ function ComposerCliMentionOverlay({
|
||||
ghostRange,
|
||||
}: {
|
||||
overlayRef: Ref<HTMLDivElement>;
|
||||
segments: CapabilityMentionSegment[];
|
||||
segments: InlineReferenceSegment[];
|
||||
isHero: boolean;
|
||||
isComposing: boolean;
|
||||
className: string;
|
||||
@@ -3023,6 +3029,13 @@ function ComposerCliMentionOverlay({
|
||||
if (segment.kind === "text") {
|
||||
return <span key={`text-${index}`}>{segment.text}</span>;
|
||||
}
|
||||
if (segment.kind === "skill") {
|
||||
return <SkillReferenceToken
|
||||
key={`skill-${segment.name}-${index}`}
|
||||
name={segment.name}
|
||||
testId={`composer-skill-reference-${segment.name.toLowerCase()}`}
|
||||
/>;
|
||||
}
|
||||
const isGhost = ghostRange?.start === start && ghostRange.end === offset;
|
||||
const identity = `${segment.kind}-${segment.kind === "cli"
|
||||
? segment.app.name : segment.kind === "mcp" ? segment.preset.name : segment.mention.session_key}`;
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
--input: 40 8% 90.5%;
|
||||
--ring: 0 0% 3.9%;
|
||||
--inline-token-highlight: #ad450b;
|
||||
--inline-reference-highlight: rgb(244 169 73);
|
||||
--code-comment: #62626b;
|
||||
--code-string: #166534;
|
||||
--code-keyword: #7e22ce;
|
||||
@@ -139,6 +140,7 @@
|
||||
--input: var(--border);
|
||||
--ring: 0 0% 83.1%;
|
||||
--inline-token-highlight: #ef8e30;
|
||||
--inline-reference-highlight: rgb(244 169 73);
|
||||
--code-comment: #c8c8d0;
|
||||
--code-string: #b5d99c;
|
||||
--code-keyword: #e3a5f7;
|
||||
@@ -1445,7 +1447,7 @@
|
||||
.automation-create-composer .thread-composer-surface {
|
||||
max-inline-size: none;
|
||||
}
|
||||
.automation-create-composer .thread-composer-input textarea {
|
||||
.automation-create-composer .thread-composer-input > :is(textarea, [aria-hidden]) {
|
||||
padding-inline: var(--settings-inset);
|
||||
}
|
||||
.automation-view-switch .segmented-control button {
|
||||
@@ -1489,7 +1491,7 @@
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.thread-composer-collapsible[data-compact] .thread-composer-input textarea {
|
||||
.thread-composer-collapsible[data-compact] .thread-composer-input > :is(textarea, [aria-hidden]) {
|
||||
display: block;
|
||||
block-size: 3.125rem !important;
|
||||
}
|
||||
@@ -1497,7 +1499,7 @@
|
||||
.thread-composer-collapsible .thread-composer-input {
|
||||
inline-size: 100%;
|
||||
}
|
||||
.thread-composer-collapsible .thread-composer-input textarea {
|
||||
.thread-composer-collapsible .thread-composer-input > :is(textarea, [aria-hidden]) {
|
||||
display: block;
|
||||
min-block-size: 3.5rem;
|
||||
padding-block: 1.125rem;
|
||||
@@ -1505,7 +1507,7 @@
|
||||
.thread-composer-collapsible[data-compact] .thread-composer-input {
|
||||
inline-size: max(0px, calc(100% - var(--composer-compact-controls-width, 15rem) - 1.5rem));
|
||||
}
|
||||
.thread-composer-collapsible[data-compact] .thread-composer-input textarea {
|
||||
.thread-composer-collapsible[data-compact] .thread-composer-input > :is(textarea, [aria-hidden]) {
|
||||
display: block;
|
||||
block-size: 3.5rem !important;
|
||||
min-block-size: 3.5rem;
|
||||
|
||||
@@ -21,10 +21,10 @@ describe("MarkdownTextRenderer", () => {
|
||||
expect(link).toHaveClass("text-blue-500", "dark:text-blue-300");
|
||||
});
|
||||
|
||||
it("renders canonical session references as same-tab links", () => {
|
||||
it.each(["#session/", "#/chat/"])("renders %s session references as same-tab links", (prefix) => {
|
||||
render(
|
||||
<MarkdownTextRenderer>
|
||||
{"We discussed this in [收费设计](#session/websocket%3Apricing)."}
|
||||
{`We discussed this in [收费设计](${prefix}websocket%3Apricing).`}
|
||||
</MarkdownTextRenderer>,
|
||||
);
|
||||
|
||||
@@ -32,7 +32,10 @@ describe("MarkdownTextRenderer", () => {
|
||||
expect(link).toHaveAttribute("href", "#/chat/websocket%3Apricing");
|
||||
expect(link).not.toHaveAttribute("target");
|
||||
expect(link.getAttribute("style")).toContain(
|
||||
"text-decoration-color: var(--inline-token-highlight)",
|
||||
"text-decoration-color: var(--inline-reference-highlight)",
|
||||
);
|
||||
expect(link.firstElementChild?.getAttribute("style")).toContain(
|
||||
"color: var(--inline-reference-highlight)",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -509,13 +509,14 @@ describe("MessageBubble", () => {
|
||||
const skill = screen.getByTestId("message-skill-reference-github");
|
||||
expect(skill).toHaveTextContent(/^\$github$/);
|
||||
expect(skill).toHaveClass(
|
||||
"font-[550]",
|
||||
"font-normal",
|
||||
"transition-colors",
|
||||
"duration-150",
|
||||
);
|
||||
expect(skill.getAttribute("style")).not.toContain("text-shadow");
|
||||
expect(skill.getAttribute("style")).toContain("var(--inline-token-highlight)");
|
||||
expect(skill.getAttribute("style")).toContain("var(--inline-reference-highlight)");
|
||||
expect(skill.className).not.toMatch(/(?:^|\s)(?:bg-|border|ring|rounded)/);
|
||||
expect(skill).not.toHaveAttribute("title");
|
||||
expect(screen.getByTestId("message-cli-mention-zoom")).toHaveTextContent("@Zoom");
|
||||
expect(skill.parentElement).toHaveTextContent("Ask $github to review this with @Zoom");
|
||||
});
|
||||
|
||||
@@ -2562,6 +2562,54 @@ describe("ThreadComposer", () => {
|
||||
}]);
|
||||
});
|
||||
|
||||
it("highlights literal skill references while preserving partial edits, clipboard text and sending", () => {
|
||||
const onSend = vi.fn();
|
||||
render(<ThreadComposer onSend={onSend} />);
|
||||
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
|
||||
const text = "like $workflow 与 $skill-creator,$";
|
||||
fireEvent.change(input, { target: { value: text, selectionStart: text.length } });
|
||||
|
||||
expect(screen.getByTestId("composer-skill-reference-workflow")).toHaveTextContent(/^\$workflow$/);
|
||||
expect(screen.getByTestId("composer-skill-reference-skill-creator")).toHaveTextContent(/^\$skill-creator$/);
|
||||
expect(input).toHaveValue(text);
|
||||
expect(input.previousElementSibling).toHaveAttribute("aria-hidden", "true");
|
||||
expect(input.previousElementSibling?.textContent).toBe(text);
|
||||
|
||||
const start = text.indexOf("workflow") + 1;
|
||||
const end = start + 4;
|
||||
input.setSelectionRange(start, end);
|
||||
const setData = vi.fn();
|
||||
fireEvent.copy(input, { clipboardData: { setData } });
|
||||
expect(setData).toHaveBeenCalledWith("text/plain", text.slice(start, end));
|
||||
fireEvent.cut(input, { clipboardData: { setData } });
|
||||
expect(input).toHaveValue(text.slice(0, start) + text.slice(end));
|
||||
fireEvent.keyDown(input, { key: "z", ctrlKey: true });
|
||||
expect(input).toHaveValue(text);
|
||||
expect(input.selectionStart).toBe(start);
|
||||
expect(input.selectionEnd).toBe(end);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
expect(onSend).toHaveBeenCalledWith(text, undefined, undefined);
|
||||
});
|
||||
|
||||
it("mirrors skill references during composition without submitting the IME confirmation", () => {
|
||||
const onSend = vi.fn();
|
||||
render(<ThreadComposer onSend={onSend} />);
|
||||
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
|
||||
fireEvent.change(input, { target: { value: "$workflow " } });
|
||||
fireEvent.compositionStart(input);
|
||||
fireEvent.change(input, { target: { value: "$workflow zhong" } });
|
||||
expect(screen.getByTestId("composer-skill-reference-workflow")).toHaveTextContent(/^\$workflow$/);
|
||||
expect(input.previousElementSibling?.textContent).toBe(input.value);
|
||||
expect(input.previousElementSibling).toHaveClass("z-20");
|
||||
fireEvent.keyDown(input, { key: "Enter", isComposing: true });
|
||||
expect(onSend).not.toHaveBeenCalled();
|
||||
fireEvent.change(input, { target: { value: "$workflow 中" } });
|
||||
fireEvent.compositionEnd(input, { data: "中" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
expect(onSend).toHaveBeenCalledWith("$workflow 中", undefined, undefined);
|
||||
});
|
||||
|
||||
it("opens skills only from a $ reference and prioritizes the skill name", () => {
|
||||
const skillName = "arxiv-intelligence-filter";
|
||||
render(
|
||||
@@ -2613,6 +2661,8 @@ describe("ThreadComposer", () => {
|
||||
fireEvent.keyDown(input, { key: "Tab" });
|
||||
|
||||
expect(input).toHaveValue(`please use $${skillName} `);
|
||||
expect(screen.getByTestId(`composer-skill-reference-${skillName}`))
|
||||
.toHaveTextContent(`$${skillName}`);
|
||||
});
|
||||
|
||||
it("ranks skill name matches ahead of earlier description matches", () => {
|
||||
@@ -2737,16 +2787,17 @@ describe("ThreadComposer", () => {
|
||||
it("keeps literal mixed-script spacing in both composer input layers", () => {
|
||||
render(<ThreadComposer onSend={vi.fn()} cliApps={CLI_APPS} />);
|
||||
const input = screen.getByLabelText("Message input");
|
||||
const value = "定位原因, 提 @gimp issue, i并提";
|
||||
const value = "定位原因, 提 @gimp issue, i并提 $workflow";
|
||||
fireEvent.change(input, { target: { value, selectionStart: value.length } });
|
||||
|
||||
const display = "定位原因, 提 @\u00a0GIMP issue, i并提";
|
||||
const display = "定位原因, 提 @\u00a0GIMP issue, i并提 $workflow";
|
||||
const overlay = input.previousElementSibling;
|
||||
expect(input).toHaveValue(display);
|
||||
expect(overlay).toHaveAttribute("aria-hidden", "true");
|
||||
expect(overlay?.textContent).toBe(display);
|
||||
expect(input).toHaveClass("[text-autospace:no-autospace]");
|
||||
expect(overlay).toHaveClass("[text-autospace:no-autospace]");
|
||||
expect(screen.getByTestId("composer-skill-reference-workflow")).toHaveTextContent("$workflow");
|
||||
});
|
||||
|
||||
it("renders a CLI app mention logo inline without moving the text cursor slot", () => {
|
||||
|
||||
Reference in new issue
Block a user