Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

studio: compact the chat composer and add animated expansion (#10863)

Maheswar Kumar536e4a8ab10d
diff --git a/studio/frontend/src/components/assistant-ui/skill-mentions.tsx b/studio/frontend/src/components/assistant-ui/skill-mentions.tsx
index 7b9449cccb7..cafddb548b3 100644
--- a/studio/frontend/src/components/assistant-ui/skill-mentions.tsx
+++ b/studio/frontend/src/components/assistant-ui/skill-mentions.tsx
@@ -15,6 +15,7 @@ import type {
import {
ComposerPrimitive,
unstable_useMentionAdapter,
+ unstable_useTriggerPopoverScopeContext,
} from "@assistant-ui/react";
import { BookOpen01Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
@@ -26,6 +27,7 @@ import {
useCallback,
useEffect,
useId,
+ useLayoutEffect,
useMemo,
useRef,
useState,
@@ -108,12 +110,29 @@ function MentionEnterSignal({
return null;
}
+// Mounted under the popover; reports whether it is open, which is when it takes Escape.
+function MentionOpenSignal({
+ onChange,
+}: {
+ onChange?: (open: boolean) => void;
+}): null {
+ const { open } = unstable_useTriggerPopoverScopeContext();
+ useLayoutEffect(() => {
+ if (!onChange) return;
+ onChange(open);
+ return () => onChange(false);
+ }, [open, onChange]);
+ return null;
+}
+
export function SkillMentionPopover({
enabled: mentionsEnabled,
onConsumesEnterChange,
+ onOpenChange,
}: {
enabled: boolean;
onConsumesEnterChange?: (consumesEnter: boolean) => void;
+ onOpenChange?: (open: boolean) => void;
}): ReactElement | null {
const t = useT();
const { skills } = useSkillsCatalog();
@@ -156,6 +175,7 @@ export function SkillMentionPopover({
<ComposerPrimitive.Unstable_TriggerPopover.Directive
{...mention.directive}
/>
+ <MentionOpenSignal onChange={onOpenChange} />
<ComposerPrimitive.Unstable_TriggerPopoverItems>
{(results) => (
<>
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 6e7fedf801b..8aa518cfc8c 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -326,6 +326,7 @@ import {
type ChangeEvent,
type CompositionEvent,
type ClipboardEvent,
+ type CSSProperties,
type FC,
type KeyboardEvent,
type DragEvent as ReactDragEvent,
@@ -338,6 +339,7 @@ import {
useCallback,
useContext,
useEffect,
+ useId,
useLayoutEffect,
useRef,
useState,
@@ -2472,6 +2474,11 @@ const Composer: FC<{
const setMentionConsumesEnter = useCallback((consumesEnter: boolean) => {
mentionConsumesEnterRef.current = consumesEnter;
}, []);
+ // True while the @skill picker is open, so Escape closes it without collapsing the composer.
+ const mentionOpenRef = useRef(false);
+ const setMentionOpen = useCallback((open: boolean) => {
+ mentionOpenRef.current = open;
+ }, []);
const { inputProps, isComposing, isComposingRef } =
useImeComposerInputHandlers({
submitOnEnter: true,
@@ -2613,6 +2620,14 @@ const Composer: FC<{
// Expand only once the input wraps to a second line, not on first keystroke.
// Latch until cleared so it can't flip-flop at the wrap boundary.
const inputRef = useRef<HTMLTextAreaElement>(null);
+ const editorRef = useRef<HTMLDivElement>(null);
+ const inputId = useId();
+ const [editorHeight, setEditorHeight] = useState(40);
+ const [isWritingExpanded, setIsWritingExpanded] = useState(false);
+ const toggleWritingExpanded = () => {
+ setIsWritingExpanded((expanded) => !expanded);
+ inputRef.current?.focus({ preventScroll: true });
+ };
// Cache line metrics so getComputedStyle runs once, not per keystroke.
const lineMetricsRef = useRef<{ lineHeight: number; padding: number } | null>(
null,
@@ -2641,6 +2656,28 @@ const Composer: FC<{
const contentHeight = el.scrollHeight - padding;
if (contentHeight > lineHeight * 1.5) setIsMultiline(true);
}, [composerText, isMultiline]);
+ // Autosize's own count: it measures a detached clone, so the expanded
+ // editor's min/max-height can't inflate it the way scrollHeight would.
+ const [editorRows, setEditorRows] = useState(1);
+ const handleEditorHeightChange = useCallback(
+ (height: number, meta: { rowHeight: number }) => {
+ setEditorHeight(height);
+ if (meta.rowHeight <= 0) return;
+ const el = inputRef.current;
+ if (el && !lineMetricsRef.current) {
+ const cs = getComputedStyle(el);
+ const lineHeight = Number.parseFloat(cs.lineHeight) || 24;
+ const padTop = Number.parseFloat(cs.paddingTop) || 0;
+ const padBottom = Number.parseFloat(cs.paddingBottom) || 0;
+ lineMetricsRef.current = { lineHeight, padding: padTop + padBottom };
+ }
+ const padding = lineMetricsRef.current?.padding ?? 0;
+ setEditorRows(Math.round((height - padding) / meta.rowHeight));
+ },
+ [],
+ );
+ // Only once the draft outgrows the compact box: a hard break, or past row 3.
+ const showWritingToggle = composerText.includes("\n") || editorRows > 3;
const hasAttachments = useAuiState(
({ composer }) => composer.attachments.length > 0,
);
@@ -3393,6 +3430,9 @@ const Composer: FC<{
// Call wherever the composer is emptied because its text left as a message.
const armJustSent = useCallback((...texts: string[]) => {
justSentRef.current = armSentTextGuard(texts, draftKeyRef.current);
+ // Here, not beside send(): handleSubmit returns early on the three queueing
+ // paths, which empty the composer too.
+ setIsWritingExpanded(false);
}, []);
const clearStoredDraft = useCallback(() => {
if (draftSaveTimerRef.current !== null) {
@@ -4452,6 +4492,27 @@ const Composer: FC<{
// a new chat first persists, which is the same composer.
const composerIdentity = threadListItemId ?? "";
composerIdentityRef.current = composerIdentity;
+ useEffect(() => {
+ setIsWritingExpanded(false);
+ }, [composerIdentity]);
+ // Window capture runs before the document listeners where the @-mention popover
+ // closes and cancelOnEscape preventDefaults every Escape (canCancel is a runtime
+ // capability, not a live run), so defaultPrevented cannot tell them apart.
+ useEffect(() => {
+ const collapseOnEscape = (event: globalThis.KeyboardEvent) => {
+ if (
+ event.key === "Escape" &&
+ !event.isComposing &&
+ !mentionOpenRef.current &&
+ event.target instanceof Node &&
+ editorRef.current?.contains(event.target)
+ ) {
+ setIsWritingExpanded(false);
+ }
+ };
+ window.addEventListener("keydown", collapseOnEscape, true);
+ return () => window.removeEventListener("keydown", collapseOnEscape, true);
+ }, []);
// Keep the mic clickable: if the engine can't run here, explain and point to
// the local model instead of disabling the button.
const startDictation = useCallback(() => {
@@ -4887,28 +4948,73 @@ const Composer: FC<{
/>
) : (
<>
- <ComposerPrimitive.Input
- placeholder={
- overlay ? "Type your edits for your image" : "Ask anything"
+ <div
+ ref={editorRef}
+ className="unsloth-composer-editor"
+ style={
+ {
+ "--composer-editor-height": `${composerText.length === 0 ? 40 : Math.max(40, editorHeight)}px`,
+ } as CSSProperties
}
- ref={inputRef}
- className="aui-composer-input unsloth-composer-input"
- minRows={1}
- maxRows={12}
- autoFocus={!disabled}
- disabled={disabled}
- aria-label={overlay ? "Image edit instructions" : "Message input"}
- // dir="auto": browser picks LTR/RTL from the first strong char;
- // no effect on Latin / CJK / Devanagari.
- dir="auto"
- {...inputProps}
- // Capture, so inputProps keeps the handlers it already owns.
- onKeyDownCapture={notePlainPasteChord}
- onKeyUpCapture={endPlainPasteChord}
- onBlurCapture={endPlainPasteChord}
- addAttachmentOnPaste={false}
- onPaste={handleFilePaste}
- />
+ >
+ <ComposerPrimitive.Input
+ id={inputId}
+ placeholder={
+ overlay ? "Type your edits for your image" : "Ask anything"
+ }
+ ref={inputRef}
+ className="aui-composer-input unsloth-composer-input"
+ minRows={1}
+ maxRows={12}
+ onHeightChange={handleEditorHeightChange}
+ autoFocus={!disabled}
+ disabled={disabled}
+ aria-label={overlay ? "Image edit instructions" : "Message input"}
+ // dir="auto": browser picks LTR/RTL from the first strong char;
+ // no effect on Latin / CJK / Devanagari.
+ dir="auto"
+ {...inputProps}
+ // Capture, so inputProps keeps the handlers it already owns.
+ onKeyDownCapture={notePlainPasteChord}
+ onKeyUpCapture={endPlainPasteChord}
+ onBlurCapture={endPlainPasteChord}
+ addAttachmentOnPaste={false}
+ onPaste={handleFilePaste}
+ />
+ {(showWritingToggle || isWritingExpanded) && (
+ <TooltipIconButton
+ type="button"
+ tooltip={
+ isWritingExpanded ? "Collapse composer" : "Expand composer"
+ }
+ aria-expanded={isWritingExpanded}
+ aria-controls={inputId}
+ disabled={disabled}
+ className="unsloth-composer-expand absolute -right-1 top-0 size-8 rounded-md bg-transparent text-muted-foreground hover:bg-transparent hover:text-muted-foreground dark:hover:bg-transparent aria-expanded:bg-transparent aria-expanded:text-muted-foreground"
+ onMouseDown={(event) => event.preventDefault()}
+ onClick={toggleWritingExpanded}
+ >
+ <svg
+ viewBox="0 0 20 20"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={2.25}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className="size-4"
+ aria-hidden={true}
+ >
+ <path
+ d={
+ isWritingExpanded
+ ? "M13 2v5h5M2 13h5v5"
+ : "M11 4h5v5M4 11v5h5"
+ }
+ />
+ </svg>
+ </TooltipIconButton>
+ )}
+ </div>
<ComposerRightControls
disabled={
disabled ||
@@ -4978,6 +5084,7 @@ const Composer: FC<{
<SkillMentionPopover
enabled={supportsTools}
onConsumesEnterChange={setMentionConsumesEnter}
+ onOpenChange={setMentionOpen}
/>
<ComposerPrimitive.Root
ref={attachComposer}
@@ -4986,6 +5093,9 @@ const Composer: FC<{
// on the toolbar instead of on the conversation.
{...{ [FIND_SKIP_ATTRIBUTE]: "" }}
className="aui-composer-root relative flex w-full flex-col"
+ data-writing-expanded={
+ isWritingExpanded && !isDictating ? "true" : undefined
+ }
aria-disabled={disabled}
onSubmit={handleSubmit}
>
@@ -5019,7 +5129,7 @@ const Composer: FC<{
no layout shift and the drop still lands. */}
<div
className={cn(
- "aui-composer-drop-overlay pointer-events-none absolute inset-0 z-20 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-[32px] bg-background/90 opacity-0 backdrop-blur-sm transition-opacity duration-150 group-data-[dragging=true]/dropzone:opacity-100 dark:bg-card/90",
+ "aui-composer-drop-overlay pointer-events-none absolute inset-0 z-20 flex flex-col items-center justify-center gap-1 overflow-hidden rounded-[inherit] bg-background/90 opacity-0 backdrop-blur-sm transition-opacity duration-150 group-data-[dragging=true]/dropzone:opacity-100 dark:bg-card/90",
pageDragging && "opacity-100",
)}
>
@@ -6780,11 +6890,10 @@ const ComposerRightControls: FC<{
aria-label="Dictate"
type="button"
variant="ghost"
- className="size-8 rounded-full text-foreground"
+ className="size-9 rounded-full text-foreground"
onClick={onDictateClick}
>
- {/* size-[22px] is the fallback; unsloth-dictate-icon sets the size. */}
- <MicIcon className="unsloth-dictate-icon size-[22px]" />
+ <MicIcon className="unsloth-dictate-icon size-6" />
</TooltipIconButton>
</ComposerPrimitive.If>
<AuiIf
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index 0ecfb2073c8..3941dccd333 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -1917,11 +1917,9 @@ html[data-chat-font] .aui-root {
font-family: var(--font-sans);
}
- /* Pill composer; own classes so compare-mode keeps its stacked layout. py
- 12px matches the send circle's gap to the right edge, so it sits evenly
- inside the 32px corner. */
+ /* 28px corner: the send circle sits at an even 10px inset inside it. */
.unsloth-composer-surface {
- @apply relative flex w-full flex-col rounded-[32px] bg-background dark:bg-card px-3 py-3 outline-none transition-shadow;
+ @apply relative flex w-full flex-col rounded-[28px] bg-background dark:bg-card p-2.5 outline-none transition-shadow;
container-type: inline-size;
font-family: var(--font-sans);
background-clip: padding-box;
@@ -1962,7 +1960,7 @@ html[data-chat-font] .aui-root {
}
.unsloth-composer-left {
- @apply flex min-w-0 flex-wrap items-center gap-0.5;
+ @apply relative top-px flex min-w-0 flex-wrap items-center gap-0.5;
order: 1;
/* Pull the plus button closer to the composer edge. Logical, so RTL
pulls it outward instead of into the action group. */
@@ -1976,7 +1974,7 @@ html[data-chat-font] .aui-root {
.unsloth-composer-line .aui-composer-action-wrapper {
order: 3;
margin-inline-start: auto;
- /* 12px surface + 4px line padding minus this = 12px edge gap. */
+ /* Cancel the line padding to preserve the surface's 10px edge gap. */
margin-inline-end: -0.25rem;
}
@@ -1985,15 +1983,13 @@ html[data-chat-font] .aui-root {
flex-basis: 100%;
width: 100%;
/* Sits close to the left edge, near the plus. */
- padding-left: 0.375rem;
+ padding-left: calc(0.375rem + 1px);
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
- /* Two-row gap between text and controls. On the line, not the input, so
- the placeholder max-height clamp never crops it like padding would. */
.unsloth-composer-line[data-expanded="true"] {
- row-gap: 0.75rem;
+ row-gap: 0.375rem;
}
.unsloth-composer-line[data-expanded="true"] .unsloth-composer-left {
@@ -2012,6 +2008,42 @@ html[data-chat-font] .aui-root {
@apply min-h-[40px] min-w-0 flex-1 resize-none overflow-y-auto bg-transparent pl-0.5 pr-2 py-2 text-ui-15 font-[450] leading-6 outline-none placeholder:text-muted-foreground focus-visible:ring-0;
}
+ /* Animate the frame so the textarea stays mounted and keeps selection/undo. */
+ .unsloth-composer-editor {
+ position: relative;
+ order: 1;
+ flex-basis: 100%;
+ width: 100%;
+ height: var(--composer-editor-height, 40px);
+ transition: height 280ms cubic-bezier(0.22, 1, 0.36, 1);
+ }
+
+ .unsloth-composer-editor .unsloth-composer-input {
+ display: block;
+ min-height: 100%;
+ max-height: 100% !important;
+ /* Reserved before typing, or the toggle appearing would reflow the text. */
+ padding-right: 2.25rem;
+ }
+
+ /* max(): at 480px tall the clamp is 192px, under the twelve-row compact
+ height, so expanding would clip. svh, since dvh tracks Safari's bar. */
+ .aui-composer-root[data-writing-expanded="true"] .unsloth-composer-editor {
+ height: max(
+ var(--composer-editor-height, 40px),
+ clamp(8rem, calc(80svh - 12rem), 42rem)
+ );
+ }
+
+ /* The welcome composer starts mid-page; move it up so the toolbar stays in view. */
+ .aui-thread-welcome-center {
+ transition: padding-top 280ms cubic-bezier(0.22, 1, 0.36, 1);
+ }
+
+ .aui-thread-welcome-center:has([data-writing-expanded="true"]) {
+ padding-top: 1rem;
+ }
+
.unsloth-composer-plus {
@apply flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full text-foreground transition-colors hover:bg-muted-foreground/15 disabled:cursor-not-allowed disabled:opacity-40;
}
@@ -2045,12 +2077,6 @@ html[data-chat-font] .aui-root {
/* Mobile and very shrunk windows: the dictate/send cluster was dropping to
a second line. Take the width back from the gutters, not the controls. */
@container composer-shell (max-width: 30rem) {
- /* Was 12px; the 32px corner still clears the plus/send circles. */
- .unsloth-composer-surface {
- padding-left: 0.5rem;
- padding-right: 0.5rem;
- }
-
.unsloth-composer-line {
padding-left: 0;
padding-right: 0;
@@ -2082,7 +2108,7 @@ html[data-chat-font] .aui-root {
/* Keeps the text starting just right of the plus glyph below it. */
.unsloth-composer-line[data-expanded="true"] .unsloth-composer-input {
- padding-left: 0.5rem;
+ padding-left: calc(0.5rem + 1px);
}
/* Recording swaps the input for the dictation bar, whose timer and
@@ -2107,14 +2133,6 @@ html[data-chat-font] .aui-root {
}
}
- /* ~400px and under: settle the control row toward the bottom edge, since
- 12px under a 32px circle is more air than the trimmed sides carry. */
- @container composer-shell (max-width: 23.5rem) {
- .unsloth-composer-surface {
- padding-bottom: 0.5rem;
- }
- }
-
/* ~375px and under. Each control is a circle around a much smaller glyph,
so the built-in air, not the gap, sets the spacing. Shrink the circles
by 4px; overlapping them instead would make adjacent hit areas share
@@ -2125,10 +2143,7 @@ html[data-chat-font] .aui-root {
}
- /* A 32px corner is a big fraction of a box this small. The drop
- overlay tracks it, or its edge shows against the surface. */
- .unsloth-composer-surface,
- .unsloth-composer-surface .aui-composer-drop-overlay {
+ .unsloth-composer-surface {
border-radius: 1.5rem;
}
@@ -2199,19 +2214,6 @@ html[data-chat-font] .aui-root {
}
}
- /* ~275px and under: trim the vertical padding and row gap so the box is no
- taller than the rows it holds. */
- @container composer-shell (max-width: 16rem) {
- .unsloth-composer-surface {
- padding-top: 0.5rem;
- padding-bottom: 0.5rem;
- }
-
- .unsloth-composer-line[data-expanded="true"] {
- row-gap: 0.5rem;
- }
- }
-
/* Keyboard focus shows a subtle brand ring, not the browser's blue outline;
mouse clicks (no :focus-visible) stay ring-free. */
.composer-pill-btn:focus-visible,
@@ -3559,17 +3561,16 @@ html[data-chat-font] .aui-root {
& svg.size-\[20px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }
& svg.size-\[21px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }
& svg.size-\[22px\] { width: var(--ui-icon-size); height: var(--ui-icon-size); }
- /* Mic and send arrow sit above the shared glyph size: both fill their
- viewBox, so they read smaller than the stroked icons beside them. Keep
- after the size-[NN] rules they override. */
+ /* Mic and send sit above the shared glyph size. Must follow size-[NN]. */
& svg.unsloth-dictate-icon {
width: calc(var(--ui-icon-size) * 1.2);
height: calc(var(--ui-icon-size) * 1.2);
+ transform: translateY(2px);
}
/* Flex centers both symmetric glyphs; pixel offsets vary by display scale. */
& svg.unsloth-send-icon {
- width: calc(var(--ui-icon-size) * 1.15);
- height: calc(var(--ui-icon-size) * 1.15);
+ width: calc(var(--ui-icon-size) * 1.3);
+ height: calc(var(--ui-icon-size) * 1.3);
}
/* Composer plus keeps its pre-#7400 22px base (1.375x the token is the same
curve a 22px glyph would follow), so only its scaling changed. */
diff --git a/studio/frontend/src/lib/mic-icon.tsx b/studio/frontend/src/lib/mic-icon.tsx
index 9ff68178454..e19fbecc85e 100644
--- a/studio/frontend/src/lib/mic-icon.tsx
+++ b/studio/frontend/src/lib/mic-icon.tsx
@@ -7,11 +7,18 @@ import type { FC } from "react";
export const MicIcon: FC<{ className?: string }> = ({ className }) => (
<svg
className={className}
- viewBox="0 0 256 256"
+ viewBox="0 0 24 24"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
+ focusable="false"
aria-hidden={true}
>
- <path d="M128,176a48.05,48.05,0,0,0,48-48V64a48,48,0,0,0-96,0v64A48.05,48.05,0,0,0,128,176ZM96,64a32,32,0,0,1,64,0v64a32,32,0,0,1-64,0Zm40,143.6V232a8,8,0,0,1-16,0V207.6A80.11,80.11,0,0,1,48,128a8,8,0,0,1,16,0,64,64,0,0,0,128,0,8,8,0,0,1,16,0A80.11,80.11,0,0,1,136,207.6Z" />
+ <path d="M18.585 13.412a.9.9 0 0 1 1.668.676 8.91 8.91 0 0 1-7.353 5.516V22a.9.9 0 0 1-1.8 0v-2.396a8.91 8.91 0 0 1-7.352-5.516.9.9 0 0 1 1.668-.676 7.104 7.104 0 0 0 13.169 0" />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ transform="translate(0 -0.425) scale(1 1.05)"
+ d="M12 1.35a4.9 4.9 0 0 1 4.9 4.9v4.483a4.9 4.9 0 0 1-9.8 0V6.25a4.9 4.9 0 0 1 4.9-4.9m0 1.8a3.1 3.1 0 0 0-3.1 3.1v4.483a3.1 3.1 0 1 0 6.2 0V6.25a3.1 3.1 0 0 0-3.1-3.1"
+ />
</svg>
);
diff --git a/studio/frontend/tests/composer-writing-expansion.test.ts b/studio/frontend/tests/composer-writing-expansion.test.ts
new file mode 100644
index 00000000000..274d9d98b7e
--- /dev/null
+++ b/studio/frontend/tests/composer-writing-expansion.test.ts
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrcAsync } from "./helpers/kit.ts";
+
+// Source-reading, like the plain-paste chord test: the invariant is where the
+// component puts one state setter.
+
+test("expansion is reset wherever the composer is emptied, not only on send", async () => {
+ const thread = await readSrcAsync("components/assistant-ui/thread.tsx");
+
+ // handleSubmit returns before send() on three queueing paths that also clear.
+ const at = thread.indexOf("const armJustSent = useCallback(");
+ assert.notEqual(at, -1, "armJustSent should still be the shared clear hook");
+ const body = thread.slice(at, thread.indexOf("\n }, [", at));
+ assert.match(body, /setIsWritingExpanded\(false\)/);
+
+ const resets = thread.match(/setIsWritingExpanded\(false\)/g) ?? [];
+ assert.equal(
+ resets.length,
+ 3,
+ "expected exactly three resets: armJustSent, the chat switch effect, and Escape",
+ );
+
+ for (const clearer of [
+ "const queueComposerText = useCallback(",
+ "const queuePastedTextPrompt = useCallback(",
+ ]) {
+ const start = thread.indexOf(clearer);
+ assert.notEqual(start, -1, `${clearer} should still exist`);
+ const region = thread.slice(start, start + 2500);
+ assert.match(region, /armJustSent\(/);
+ }
+});
+
+test("Escape collapses unless it closes the mention popover", async () => {
+ const thread = await readSrcAsync("components/assistant-ui/thread.tsx");
+ const mentions = await readSrcAsync(
+ "components/assistant-ui/skill-mentions.tsx",
+ );
+
+ // cancelOnEscape preventDefaults every Escape on the document, so a
+ // defaultPrevented gate never collapses. Decide from the window, before it.
+ const at = thread.indexOf("const collapseOnEscape = (");
+ assert.notEqual(at, -1);
+ const body = thread.slice(at, thread.indexOf("\n }, []);", at));
+ assert.match(body, /event\.key === "Escape"/);
+ assert.match(body, /!event\.isComposing/);
+ assert.match(body, /!mentionOpenRef\.current/);
+ assert.match(body, /editorRef\.current\?\.contains\(event\.target\)/);
+ assert.doesNotMatch(body, /defaultPrevented/);
+ assert.match(
+ body,
+ /window\.addEventListener\("keydown", collapseOnEscape, true\)/,
+ );
+ assert.match(thread, /onOpenChange=\{setMentionOpen\}/);
+
+ // The same open flag the popover's own Escape handling checks.
+ assert.match(
+ mentions,
+ /const \{ open \} = unstable_useTriggerPopoverScopeContext\(\);/,
+ );
+ assert.match(mentions, /<MentionOpenSignal onChange=\{onOpenChange\} \/>/);
+
+ // The input's capture slot stays the plain-paste chord's (pasted-text-attachment.test.ts).
+ const editor = thread.indexOf('className="unsloth-composer-editor"');
+ const wrapper = thread.slice(
+ editor,
+ thread.indexOf("<ComposerPrimitive.Input", editor),
+ );
+ assert.doesNotMatch(wrapper, /onKeyDownCapture/);
+});