feat(webui): expand long drafts and refine chat scrollbars (#6709)
* feat(webui): expand long drafts and refine chat scrollbars * test(webui): synchronize browser setup and isolate locale cases * test(webui): wait for the About fixture before measuring layout
This commit is contained in:
1 parent
db430df3f6
commit
cab49a1c66
20 files changed
+271
-59
No files matched your search
@@ -8,9 +8,10 @@ test("About current-version feedback keeps its initial row height with wider sys
|
||||
for (const state of ["loaded", "loading"]) {
|
||||
await page.goto(`/browser/fixture.html?case=skeleton-additions&surface=settings&state=${state}§ion=about`);
|
||||
await page.addStyleTag({ content: "body { font-family: monospace; }" });
|
||||
if (state === "loaded") await expect(page.getByText("You're up to date", { exact: true })).toBeVisible();
|
||||
// Wait for the lazy About panel before measuring the row.
|
||||
if (state === "loaded") await page.getByText("You're up to date", { exact: true }).waitFor();
|
||||
const row = page.locator("[data-settings-section] .settings-list-row").first();
|
||||
await expect(row).toBeVisible();
|
||||
await row.waitFor();
|
||||
positions.push((await row.boundingBox())!.y);
|
||||
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
|
||||
}
|
||||
@@ -30,7 +31,7 @@ for (const state of ["loaded", "loading"]) {
|
||||
try {
|
||||
await page.goto(`/browser/fixture.html?case=skeleton-additions&surface=settings&state=${state}§ion=about`, { waitUntil: "domcontentloaded" });
|
||||
const row = page.locator("[data-settings-section] .settings-list-row").first();
|
||||
await expect(row).toBeVisible();
|
||||
await row.waitFor();
|
||||
const before = await row.boundingBox();
|
||||
release();
|
||||
const wordmark = page.locator('img[alt="nanobot"]');
|
||||
|
||||
@@ -19,7 +19,8 @@ async function openThread(page: Page) {
|
||||
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
|
||||
await page.route("**/api/sessions/*/webui-thread?*", route => route.fulfill({ json: history }));
|
||||
await page.goto("/browser/fixture.html?case=thread-loading");
|
||||
await expect(page.getByRole("heading", { name: "Section 25", exact: true })).toBeVisible();
|
||||
// Let the lazy Markdown renderer settle before measuring transcript geometry.
|
||||
await page.getByRole("heading", { name: "Section 25", exact: true }).waitFor();
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
||||
await input.fill("Next steps:\n1. Check layout\n2. ");
|
||||
@@ -88,6 +89,52 @@ test("autosizing still grows, caps and shrinks the real input", async ({ page })
|
||||
await expect.poll(() => scroller.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeLessThanOrEqual(1);
|
||||
});
|
||||
|
||||
for (const viewport of [{ width: 1440, height: 900 }, { width: 390, height: 500 }]) {
|
||||
test(`overflowing drafts can be expanded and collapsed in place at ${viewport.width}px`, async ({ page }) => {
|
||||
await page.setViewportSize(viewport);
|
||||
const { input } = await openThread(page);
|
||||
const expand = page.getByRole("button", { name: "Expand editor" });
|
||||
const collapse = page.getByRole("button", { name: "Collapse editor" });
|
||||
const footer = page.locator(".thread-composer-footer");
|
||||
const selection = () => input.evaluate(node => {
|
||||
const { selectionStart, selectionEnd } = node as HTMLTextAreaElement;
|
||||
return [selectionStart, selectionEnd];
|
||||
});
|
||||
await expect(expand).not.toBeVisible();
|
||||
const draft = ["Which warnings should I fix?", ...Array.from({ length: 11 }, (_, i) => `Line ${i + 1}: build output`)].join("\n");
|
||||
await input.fill(draft);
|
||||
await expect(expand).toBeVisible();
|
||||
const smallHeight = await input.evaluate(node => node.clientHeight);
|
||||
const footerBounds = await footer.boundingBox();
|
||||
await input.press("Control+End");
|
||||
await expect.poll(() => input.evaluate(node => node.scrollTop)).toBeGreaterThan(0);
|
||||
expect(await footer.boundingBox()).toEqual(footerBounds);
|
||||
|
||||
await expand.click();
|
||||
await expect(collapse).toHaveAttribute("aria-expanded", "true");
|
||||
await expect(input).toBeFocused();
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(smallHeight + 24);
|
||||
expect(await selection()).toEqual([draft.length, draft.length]);
|
||||
const expandedFooter = (await footer.boundingBox())!;
|
||||
expect(expandedFooter.y + expandedFooter.height).toBeLessThanOrEqual(viewport.height);
|
||||
expect(await input.evaluate(node => node.scrollHeight)).toBe(await input.evaluate(node => node.clientHeight));
|
||||
await collapse.click();
|
||||
await expect(expand).toBeVisible();
|
||||
await expect.poll(() => input.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeLessThanOrEqual(1);
|
||||
|
||||
await expand.click();
|
||||
await input.press("Control+Home");
|
||||
await input.press("Shift+End");
|
||||
const firstLine = [0, draft.indexOf("\n")];
|
||||
expect(await selection()).toEqual(firstLine);
|
||||
await collapse.press("Enter");
|
||||
await expect(input).toBeFocused();
|
||||
await expect(input).toHaveValue(draft);
|
||||
expect(await selection()).toEqual(firstLine);
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(smallHeight);
|
||||
});
|
||||
}
|
||||
|
||||
test("Chromium IME composition and commit keep the transcript stationary", async ({ page }) => {
|
||||
const { input } = await openThread(page);
|
||||
const original = await input.inputValue();
|
||||
|
||||
@@ -73,6 +73,9 @@ const group = groups.find(({ id }) => id === params.get("group")) ?? groups[0]!;
|
||||
const base = loadCodexCatalog
|
||||
? preset("Review", "openai_codex", "openai-codex/gpt-6.2-sol", "xhigh", ["low", "medium", "high"], { default: false, ultrafast_supported: true })
|
||||
: group.id === "oauth" ? (params.has("ultrafast") ? ultrafastCodex : standardCodex) : group.presets[0]!;
|
||||
const extraPresets = params.has("many-presets")
|
||||
? Array.from({ length: 12 }, (_, index) => preset(`Example ${index + 1}`, "openai_codex", "gpt-6.2-sol"))
|
||||
: [];
|
||||
const settings: SettingsPayload = {
|
||||
...baseSettings,
|
||||
agent: { ...baseSettings.agent, model: base.model, provider: base.provider, resolved_provider: base.provider,
|
||||
@@ -80,8 +83,8 @@ const settings: SettingsPayload = {
|
||||
providers: Object.entries(providers).map(([name, provider]) => ({
|
||||
name, configured: true, model_catalog: loadCodexCatalog && name === "openai_codex" ? "hybrid" : "unsupported", ...provider,
|
||||
})),
|
||||
model_presets: [{ ...base, name: "default", label: "Default", active: true, is_default: true }, ...group.presets],
|
||||
model_call_order: group.presets.map(({ name }) => name),
|
||||
model_presets: [{ ...base, name: "default", label: "Default", active: true, is_default: true }, ...group.presets, ...extraPresets],
|
||||
model_call_order: [...group.presets, ...extraPresets].map(({ name }) => name),
|
||||
};
|
||||
|
||||
function fixtureLink(groupId: string, settingsView: boolean) {
|
||||
|
||||
@@ -88,6 +88,33 @@ for (const width of [390, 1280]) {
|
||||
});
|
||||
}
|
||||
|
||||
test("a long preset list scrolls without moving the model controls in a short viewport", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 390, height: 380 });
|
||||
await page.goto("/browser/fixture.html?case=model-options&many-presets&ultrafast");
|
||||
await page.getByRole("button", { name: "Default", exact: true }).click();
|
||||
const dialog = page.getByRole("dialog", { name: "Switch model", exact: true });
|
||||
const list = dialog.getByRole("listbox");
|
||||
const effort = dialog.getByRole("slider", { name: "Reasoning effort" });
|
||||
const manage = dialog.getByRole("button", { name: "Manage presets" });
|
||||
await dialog.evaluate((node) => Promise.all(node.getAnimations().map((animation) => animation.finished)));
|
||||
await expect(manage).toBeInViewport({ ratio: 1 });
|
||||
expect(await dialog.evaluate((node) => node.scrollHeight - node.clientHeight)).toBeLessThanOrEqual(1);
|
||||
const effortBefore = await effort.boundingBox();
|
||||
const manageBefore = await manage.boundingBox();
|
||||
await list.hover();
|
||||
await page.mouse.wheel(0, 100);
|
||||
await expect.poll(() => list.evaluate((node) => node.scrollTop)).toBeGreaterThan(0);
|
||||
expect(await effort.boundingBox()).toEqual(effortBefore);
|
||||
expect(await manage.boundingBox()).toEqual(manageBefore);
|
||||
|
||||
await list.getByRole("option", { name: "default", exact: true }).press("End");
|
||||
const last = list.getByRole("option", { name: "Example 12", exact: true });
|
||||
await expect(last).toBeFocused();
|
||||
await expect(last).toBeInViewport({ ratio: 0.9 });
|
||||
await last.press("Enter");
|
||||
await expect(page.getByRole("button", { name: "Example 12", exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("Temporary Chats do not expose model option controls", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=model-options&temporary");
|
||||
await page.getByRole("button", { name: "Default", exact: true }).click();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { supportedLocales } from "../src/i18n/config";
|
||||
|
||||
async function selectRadio(page: Page, group: string, name: string) {
|
||||
const radio = page.getByRole("radiogroup", { name: group }).getByRole("radio", { name, exact: true });
|
||||
@@ -106,36 +107,37 @@ test("reveals MCP tools hidden by Ready only without switching tool type", async
|
||||
});
|
||||
|
||||
|
||||
test("keeps Apps section controls usable on narrow screens in each locale", async ({ page }) => {
|
||||
const width = 320;
|
||||
await page.setViewportSize({ width, height: 800 });
|
||||
await page.route("**/api/settings/cli-apps", route => route.fulfill({ json: { apps: [], installed_count: 0 } }));
|
||||
await page.route("**/api/settings/mcp-presets", route => route.fulfill({ json: { presets: [], installed_count: 0 } }));
|
||||
await page.route("**/api/settings/nanobot-features", route => route.fulfill({ json: { features: [], enabled_count: 0 } }));
|
||||
await page.route("**/api/webui/skills/trending?**", route => route.fulfill({ json: { skills: [] } }));
|
||||
const controls = page.locator(".catalog-controls");
|
||||
async function expectControlsFit(locale: string, count: number) {
|
||||
const targets = page.locator(".catalog-tabs > button, .catalog-controls label");
|
||||
await expect(targets).toHaveCount(count);
|
||||
const geometry = await targets.evaluateAll(elements => elements.map(element => {
|
||||
const bounds = element.getBoundingClientRect();
|
||||
return {
|
||||
label: element.textContent,
|
||||
left: bounds.left,
|
||||
right: bounds.right,
|
||||
fits: element.scrollWidth <= element.clientWidth
|
||||
&& (!element.matches("button") || element.scrollHeight <= element.clientHeight),
|
||||
};
|
||||
}));
|
||||
expect(geometry.filter(item => item.left < 0 || item.right > width || !item.fits), locale).toEqual([]);
|
||||
}
|
||||
for (const locale of ["en", "es", "fr", "id", "ja", "ko", "pt-BR", "vi", "zh-CN", "zh-TW"]) {
|
||||
for (const { code: locale } of supportedLocales) {
|
||||
test(`keeps Apps section controls usable on narrow screens in ${locale}`, async ({ page }) => {
|
||||
const width = 320;
|
||||
await page.setViewportSize({ width, height: 800 });
|
||||
await page.route("**/api/settings/cli-apps", route => route.fulfill({ json: { apps: [], installed_count: 0 } }));
|
||||
await page.route("**/api/settings/mcp-presets", route => route.fulfill({ json: { presets: [], installed_count: 0 } }));
|
||||
await page.route("**/api/settings/nanobot-features", route => route.fulfill({ json: { features: [], enabled_count: 0 } }));
|
||||
await page.route("**/api/webui/skills/trending?**", route => route.fulfill({ json: { skills: [] } }));
|
||||
const controls = page.locator(".catalog-controls");
|
||||
async function expectControlsFit(count: number) {
|
||||
const targets = page.locator(".catalog-tabs > button, .catalog-controls label");
|
||||
await expect(targets).toHaveCount(count);
|
||||
const geometry = await targets.evaluateAll(elements => elements.map(element => {
|
||||
const bounds = element.getBoundingClientRect();
|
||||
return {
|
||||
label: element.textContent,
|
||||
left: bounds.left,
|
||||
right: bounds.right,
|
||||
fits: element.scrollWidth <= element.clientWidth
|
||||
&& (!element.matches("button") || element.scrollHeight <= element.clientHeight),
|
||||
};
|
||||
}));
|
||||
expect(geometry.filter(item => item.left < 0 || item.right > width || !item.fits)).toEqual([]);
|
||||
}
|
||||
|
||||
await page.goto(`/browser/fixture.html?case=tools-catalog&lang=${locale}`);
|
||||
const types = page.getByRole("radiogroup").getByRole("radio");
|
||||
const status = controls.getByRole("switch");
|
||||
await expect(types).toHaveCount(4);
|
||||
await expect(status).not.toBeChecked();
|
||||
await expectControlsFit(locale, 8);
|
||||
await expectControlsFit(8);
|
||||
const cli = types.nth(1);
|
||||
await cli.locator("..").click();
|
||||
await expect(cli).toBeChecked();
|
||||
@@ -153,20 +155,20 @@ test("keeps Apps section controls usable on narrow screens in each locale", asyn
|
||||
|
||||
const sections = page.locator(".catalog-tabs").getByRole("button");
|
||||
await sections.nth(1).click();
|
||||
await expectControlsFit(locale, 8);
|
||||
await expectControlsFit(8);
|
||||
const marketplace = controls.getByRole("radio").nth(1);
|
||||
await marketplace.locator("..").click();
|
||||
await expect(marketplace).toBeFocused();
|
||||
await expect(marketplace).toBeChecked();
|
||||
await expectControlsFit(locale, 8);
|
||||
await expectControlsFit(8);
|
||||
|
||||
await sections.nth(2).click();
|
||||
await expectControlsFit(locale, 4);
|
||||
await expectControlsFit(4);
|
||||
await status.locator("..").locator(":scope > span").click();
|
||||
await expect(status).toBeChecked();
|
||||
await expect(status).toBeFocused();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
test("opens the generated plugin from its CLI app", async ({ page }) => {
|
||||
|
||||
@@ -248,6 +248,7 @@ export function AutomationsSettings({
|
||||
"What would you like nanobot to automate?",
|
||||
)}
|
||||
variant="thread"
|
||||
expandable={false}
|
||||
compactWhenIdle
|
||||
modelLabel={modelBadgeLabel}
|
||||
modelDetail={modelBadge.model}
|
||||
|
||||
@@ -134,7 +134,7 @@ export function ModelOptionsControl({ data, onChange }: ModelOptionsControlProps
|
||||
const options = defaultEffort === null ? [null, ...values] : values;
|
||||
const mode = values.every((effort) => efforts.includes(effort)) ? "ordered" : effortsPending ? "pending" : "custom";
|
||||
return (
|
||||
<div className="model-options-row mt-1 flex items-center gap-1 border-t border-border/55 px-2 py-1">
|
||||
<div className="model-options-row mt-1 flex shrink-0 items-center gap-1 border-t border-border/55 px-2 py-1">
|
||||
{values.length > 0 ? (
|
||||
<ReasoningEffortControl options={options} selected={options.indexOf(effectiveEffort)}
|
||||
mode={mode}
|
||||
|
||||
@@ -433,7 +433,7 @@ export function ModelPresetBadge({
|
||||
}}
|
||||
className={cn(
|
||||
showsSpeedControl ? speedPickerWidthClassName : pickerWidthClassName,
|
||||
"max-h-[var(--radix-popover-content-available-height)] overflow-y-auto",
|
||||
"inset-scrollbar flex max-h-[var(--radix-popover-content-available-height)] flex-col overflow-y-auto",
|
||||
"origin-[var(--radix-popover-content-transform-origin)] p-1.5 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-bottom-1 data-[state=open]:slide-in-from-bottom-1 duration-200 ease-out motion-reduce:animate-none",
|
||||
)}
|
||||
>
|
||||
@@ -451,7 +451,7 @@ export function ModelPresetBadge({
|
||||
event.preventDefault();
|
||||
options[wrapIndex(target, options.length)].focus();
|
||||
}}
|
||||
className="max-h-[min(16rem,var(--radix-popover-content-available-height))] overflow-y-auto py-1 scrollbar-thin scrollbar-track-transparent"
|
||||
className="inset-scrollbar min-h-11 max-h-64 overflow-y-auto py-1 [scrollbar-gutter:stable]"
|
||||
>
|
||||
{pickerPresets.map((preset) => (
|
||||
<PresetOption
|
||||
@@ -465,7 +465,7 @@ export function ModelPresetBadge({
|
||||
</div>
|
||||
{modelOptionsControl ? <ModelOptionsControl {...modelOptionsControl} /> : null}
|
||||
{onManageModels ? (
|
||||
<div className="mt-1 border-t border-border/55 pt-1">
|
||||
<div className="mt-1 shrink-0 border-t border-border/55 pt-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={openModelSettings}
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useId,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
@@ -58,6 +59,8 @@ import { SlashCommandText } from "@/components/SlashCommandText";
|
||||
import {
|
||||
CornerDownRight,
|
||||
Loader2,
|
||||
Maximize2,
|
||||
Minimize2,
|
||||
Quote,
|
||||
Trash2,
|
||||
X,
|
||||
@@ -223,6 +226,7 @@ interface ThreadComposerProps {
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
inputAriaLabel?: string;
|
||||
expandable?: boolean;
|
||||
compactWhenIdle?: boolean;
|
||||
isStreaming?: boolean;
|
||||
activeTurnId?: string | null;
|
||||
@@ -537,12 +541,14 @@ function mcpPresetMentionPayload(preset: McpPresetInfo): OutboundMcpPresetMentio
|
||||
function autosizeTextarea(input: HTMLTextAreaElement) {
|
||||
const container = input.parentElement!;
|
||||
const previousMinHeight = container.style.minHeight;
|
||||
const scrollTop = input.scrollTop;
|
||||
// Measuring the one-row textarea must not expand the sibling transcript and
|
||||
// clamp its native scroll offset, even temporarily before paint.
|
||||
container.style.minHeight = `${container.getBoundingClientRect().height}px`;
|
||||
try {
|
||||
input.style.height = "auto";
|
||||
input.style.height = `${Math.min(input.scrollHeight, 260)}px`;
|
||||
input.style.height = `${input.scrollHeight}px`;
|
||||
input.scrollTop = scrollTop;
|
||||
} finally {
|
||||
container.style.minHeight = previousMinHeight;
|
||||
}
|
||||
@@ -553,6 +559,7 @@ export function ThreadComposer({
|
||||
disabled,
|
||||
placeholder,
|
||||
inputAriaLabel,
|
||||
expandable = true,
|
||||
compactWhenIdle = false,
|
||||
isStreaming = false,
|
||||
activeTurnId = null,
|
||||
@@ -633,6 +640,9 @@ export function ThreadComposer({
|
||||
useEffect(() => () => { pathCheckGeneration.current += 1; }, []);
|
||||
const [modelSetupAttentionRequest, setModelSetupAttentionRequest] = useState(0);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const textareaId = useId();
|
||||
const [draftExpanded, setDraftExpanded] = useState(false);
|
||||
const [draftOverflows, setDraftOverflows] = useState(false);
|
||||
const focusTextarea = useCallback(() => {
|
||||
requestAnimationFrame(() => textareaRef.current?.focus());
|
||||
}, []);
|
||||
@@ -731,27 +741,40 @@ export function ThreadComposer({
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const [compactControls, setCompactControls] = useState(false);
|
||||
|
||||
const measureDraft = useCallback(() => {
|
||||
const input = textareaRef.current;
|
||||
if (!input) return;
|
||||
autosizeTextarea(input);
|
||||
if (expandable) setDraftOverflows(input.scrollHeight > input.clientHeight);
|
||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = input.scrollTop;
|
||||
}, [expandable]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const form = formRef.current;
|
||||
if (!form) return;
|
||||
const input = textareaRef.current;
|
||||
if (!form || !input) return;
|
||||
let previousWidth = 0;
|
||||
const update = () => {
|
||||
const width = form.getBoundingClientRect().width;
|
||||
if (width <= 0 || width === previousWidth) return;
|
||||
previousWidth = width;
|
||||
setCompactControls(width <= 512);
|
||||
const input = textareaRef.current;
|
||||
if (input) autosizeTextarea(input);
|
||||
if (width <= 0) return;
|
||||
if (width !== previousWidth) {
|
||||
previousWidth = width;
|
||||
setCompactControls(width <= 512);
|
||||
measureDraft();
|
||||
} else if (expandable) {
|
||||
setDraftOverflows(input.scrollHeight > input.clientHeight);
|
||||
}
|
||||
};
|
||||
update();
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
|
||||
observer?.observe(form);
|
||||
if (expandable) observer?.observe(input);
|
||||
window.addEventListener("resize", update);
|
||||
return () => {
|
||||
observer?.disconnect();
|
||||
window.removeEventListener("resize", update);
|
||||
};
|
||||
}, []);
|
||||
}, [expandable, measureDraft]);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const chipRefs = useRef(new Map<string, HTMLButtonElement>());
|
||||
const previousPendingQueueKeyRef = useRef(pendingQueueKey);
|
||||
@@ -1376,17 +1399,15 @@ export function ThreadComposer({
|
||||
}, [filteredMentionCandidates.length, filteredSlashCommands.length, showAnyPalette]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const el = textareaRef.current;
|
||||
if (!el || mentionInput.isComposing) return;
|
||||
autosizeTextarea(el);
|
||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = el.scrollTop;
|
||||
}, [compactControls, mentionInput.isComposing, mentionInput.value]);
|
||||
if (mentionInput.isComposing) return;
|
||||
if (!mentionInput.value) setDraftExpanded(false);
|
||||
measureDraft();
|
||||
}, [compactControls, measureDraft, mentionInput.isComposing, mentionInput.value]);
|
||||
|
||||
useEffect(() => {
|
||||
// The parent projects typography tokens in its layout effect; measure after it.
|
||||
const input = textareaRef.current;
|
||||
if (input) autosizeTextarea(input);
|
||||
}, [readingTextSize, customReadingTextSize]);
|
||||
measureDraft();
|
||||
}, [readingTextSize, customReadingTextSize, measureDraft]);
|
||||
|
||||
// Runs before paint so switching sessions never flashes stale draft text.
|
||||
useLayoutEffect(() => {
|
||||
@@ -1998,8 +2019,8 @@ export function ThreadComposer({
|
||||
const usageControl = !voiceRecorder.isRecording
|
||||
? renderContextUsage?.({ showLabel: usageInMeta, compactLabel: mobileWorkspaceControls }) : null;
|
||||
const inputTextClasses = cn(
|
||||
// Keep the overlay's CJK/Latin spacing aligned with the native textarea caret.
|
||||
"w-full resize-none bg-transparent text-composer [text-autospace:no-autospace]",
|
||||
// The native input and its reference overlay must wrap and space text alike.
|
||||
"inset-scrollbar w-full resize-none bg-transparent text-composer [scrollbar-gutter:stable] [text-autospace:no-autospace]",
|
||||
compactControls
|
||||
? "min-h-[52px] px-4 pb-2 pt-3"
|
||||
: isHero
|
||||
@@ -2010,6 +2031,16 @@ export function ThreadComposer({
|
||||
: "min-h-[50px] px-3.5 pb-1.5 pt-3 sm:px-4",
|
||||
);
|
||||
const paletteBeside = showAnyPalette && slashPaletteLayout.placement === "beside";
|
||||
const draftResizeLabel = t(draftExpanded ? "thread.composer.collapseDraft" : "thread.composer.expandDraft");
|
||||
const toggleDraftSize = () => {
|
||||
const input = textareaRef.current;
|
||||
if (!input) return;
|
||||
const followCaret = draftExpanded && input.selectionStart === input.value.length
|
||||
&& input.scrollHeight - input.clientHeight - input.scrollTop <= 1;
|
||||
setDraftExpanded(!draftExpanded);
|
||||
input.focus({ preventScroll: true });
|
||||
if (followCaret) requestAnimationFrame(() => { input.scrollTop = input.scrollHeight; });
|
||||
};
|
||||
|
||||
return (
|
||||
<form
|
||||
@@ -2164,7 +2195,12 @@ export function ThreadComposer({
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="thread-composer-input relative min-w-0">
|
||||
<div
|
||||
className="thread-composer-input relative min-w-0"
|
||||
data-expandable={expandable || undefined}
|
||||
data-expanded={draftExpanded || undefined}
|
||||
data-overflowing={draftOverflows || undefined}
|
||||
>
|
||||
{placeholder === undefined ? (
|
||||
<span className="pointer-events-none invisible absolute h-0 w-0 overflow-hidden">
|
||||
<span ref={placeholderMeasureRef} aria-hidden className="inline-block whitespace-pre text-composer [text-autospace:no-autospace]">{resolvedPlaceholder}</span>
|
||||
@@ -2184,6 +2220,7 @@ export function ThreadComposer({
|
||||
/>
|
||||
) : null}
|
||||
<textarea
|
||||
id={textareaId}
|
||||
ref={textareaRef}
|
||||
value={mentionInput.value}
|
||||
onFocus={() => {
|
||||
@@ -2278,6 +2315,29 @@ export function ThreadComposer({
|
||||
isHero ? "gap-1.5" : "gap-2",
|
||||
)}
|
||||
>
|
||||
{expandable && (draftExpanded || draftOverflows) ? (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="icon"
|
||||
disabled={interactionDisabled}
|
||||
aria-label={draftResizeLabel}
|
||||
aria-expanded={draftExpanded}
|
||||
aria-controls={textareaId}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={toggleDraftSize}
|
||||
className="thread-composer-action thread-composer-round-action touch-target h-[var(--composer-action-size)] w-[var(--composer-action-size)] shrink-0 rounded-xl text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{draftExpanded ? <Minimize2 className="h-3.5 w-3.5" /> : <Maximize2 className="h-3.5 w-3.5" />}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{draftResizeLabel}</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
) : null}
|
||||
{modelControl}
|
||||
{!usageInMeta ? usageControl : null}
|
||||
<TooltipProvider>
|
||||
|
||||
@@ -919,6 +919,43 @@
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* Keep the native drag target wider than the visible thumb. */
|
||||
@media (forced-colors: none) {
|
||||
@supports selector(::-webkit-scrollbar) {
|
||||
html:not(.native-host) .inset-scrollbar {
|
||||
scrollbar-width: auto;
|
||||
scrollbar-color: auto;
|
||||
}
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar {
|
||||
width: 14px;
|
||||
}
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar-button {
|
||||
display: none;
|
||||
}
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar-track {
|
||||
margin-block: 6px;
|
||||
background: transparent;
|
||||
}
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar-thumb {
|
||||
min-height: 28px;
|
||||
border-inline: 4px solid transparent;
|
||||
border-inline-end-width: 6px;
|
||||
border-radius: 999px;
|
||||
background: var(--scrollbar-thumb) padding-box;
|
||||
}
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar-thumb:hover,
|
||||
html:not(.native-host) .inset-scrollbar::-webkit-scrollbar-thumb:active {
|
||||
background-color: var(--scrollbar-thumb-hover);
|
||||
}
|
||||
}
|
||||
}
|
||||
@media (forced-colors: active) {
|
||||
html:not(.native-host) .inset-scrollbar {
|
||||
scrollbar-width: auto;
|
||||
scrollbar-color: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mobile responsive safety net — keep the chat viewport + composer inside a
|
||||
* narrow viewport (see #4693). These are containment rules: long markdown
|
||||
@@ -1522,6 +1559,20 @@
|
||||
.thread-composer-collapsible-layout {
|
||||
container: composer-layout / inline-size;
|
||||
}
|
||||
.thread-composer-input[data-expandable] {
|
||||
--composer-edit-room: max(6rem, calc(var(--app-viewport-height, 100dvh) - 11rem));
|
||||
--composer-input-limit: min(260px, calc(var(--composer-edit-room) * 0.7));
|
||||
}
|
||||
.thread-composer-input[data-expanded] {
|
||||
--composer-input-limit: min(38rem, var(--composer-edit-room));
|
||||
}
|
||||
.thread-composer-input:is([data-overflowing], [data-expanded]) {
|
||||
margin-block: 0.375rem;
|
||||
}
|
||||
.thread-composer-input > textarea {
|
||||
max-height: var(--composer-input-limit, 260px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
/* A wrapped placeholder must not resize the empty composer. */
|
||||
.thread-composer-input textarea:placeholder-shown {
|
||||
overflow: hidden;
|
||||
|
||||
@@ -2133,6 +2133,8 @@
|
||||
"cancelGoal": "Cancel goal",
|
||||
"cancelGoalFailed": "Could not cancel goal. Try again.",
|
||||
"cancelGoalOffline": "Reconnect to cancel the goal.",
|
||||
"expandDraft": "Expand editor",
|
||||
"collapseDraft": "Collapse editor",
|
||||
"send": "Send message",
|
||||
"stop": "Stop response",
|
||||
"quotedContext": "Quoted context",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "Cancelar objetivo",
|
||||
"cancelGoalFailed": "No se pudo cancelar. Inténtalo de nuevo.",
|
||||
"cancelGoalOffline": "Vuelve a conectarte para cancelar el objetivo.",
|
||||
"expandDraft": "Ampliar el área de escritura",
|
||||
"collapseDraft": "Reducir el área de escritura",
|
||||
"send": "Enviar mensaje",
|
||||
"stop": "Detener respuesta",
|
||||
"quotedContext": "Contexto citado",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "Annuler l’objectif",
|
||||
"cancelGoalFailed": "Échec de l’annulation. Réessayez.",
|
||||
"cancelGoalOffline": "Reconnectez-vous pour annuler l’objectif.",
|
||||
"expandDraft": "Agrandir la zone de saisie",
|
||||
"collapseDraft": "Réduire la zone de saisie",
|
||||
"send": "Envoyer le message",
|
||||
"stop": "Arrêter la réponse",
|
||||
"quotedContext": "Contexte cité",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "Batalkan tujuan",
|
||||
"cancelGoalFailed": "Tujuan gagal dibatalkan. Coba lagi.",
|
||||
"cancelGoalOffline": "Hubungkan kembali untuk membatalkan tujuan.",
|
||||
"expandDraft": "Perluas kotak pesan",
|
||||
"collapseDraft": "Perkecil kotak pesan",
|
||||
"send": "Kirim pesan",
|
||||
"stop": "Hentikan respons",
|
||||
"quotedContext": "Konteks kutipan",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "目標を取り消す",
|
||||
"cancelGoalFailed": "取り消せませんでした。再試行してください。",
|
||||
"cancelGoalOffline": "再接続してから目標を取り消してください。",
|
||||
"expandDraft": "入力欄を広げる",
|
||||
"collapseDraft": "入力欄を折りたたむ",
|
||||
"send": "メッセージを送信",
|
||||
"stop": "応答を停止",
|
||||
"quotedContext": "引用したコンテキスト",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "목표 취소",
|
||||
"cancelGoalFailed": "목표를 취소하지 못했습니다. 다시 시도하세요.",
|
||||
"cancelGoalOffline": "다시 연결한 후 목표를 취소하세요.",
|
||||
"expandDraft": "입력창 펼치기",
|
||||
"collapseDraft": "입력창 접기",
|
||||
"send": "메시지 보내기",
|
||||
"stop": "응답 중지",
|
||||
"quotedContext": "인용한 문맥",
|
||||
|
||||
@@ -1953,6 +1953,8 @@
|
||||
"cancelGoal": "Cancelar objetivo",
|
||||
"cancelGoalFailed": "Não foi possível cancelar. Tente novamente.",
|
||||
"cancelGoalOffline": "Reconecte-se para cancelar o objetivo.",
|
||||
"expandDraft": "Expandir a área de edição",
|
||||
"collapseDraft": "Recolher a área de edição",
|
||||
"send": "Enviar mensagem",
|
||||
"stop": "Parar resposta",
|
||||
"quotedContext": "Contexto citado",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "Hủy mục tiêu",
|
||||
"cancelGoalFailed": "Không thể hủy mục tiêu. Hãy thử lại.",
|
||||
"cancelGoalOffline": "Kết nối lại để hủy mục tiêu.",
|
||||
"expandDraft": "Mở rộng ô soạn thảo",
|
||||
"collapseDraft": "Thu gọn ô soạn thảo",
|
||||
"send": "Gửi tin nhắn",
|
||||
"stop": "Dừng phản hồi",
|
||||
"quotedContext": "Ngữ cảnh được trích dẫn",
|
||||
|
||||
@@ -2133,6 +2133,8 @@
|
||||
"cancelGoal": "取消目标",
|
||||
"cancelGoalFailed": "取消失败,请重试。",
|
||||
"cancelGoalOffline": "请重新连接后取消目标。",
|
||||
"expandDraft": "展开编辑",
|
||||
"collapseDraft": "收起编辑",
|
||||
"send": "发送消息",
|
||||
"stop": "停止响应",
|
||||
"quotedContext": "引用内容",
|
||||
|
||||
@@ -1951,6 +1951,8 @@
|
||||
"cancelGoal": "取消目標",
|
||||
"cancelGoalFailed": "取消失敗,請重試。",
|
||||
"cancelGoalOffline": "請重新連線後取消目標。",
|
||||
"expandDraft": "展開編輯",
|
||||
"collapseDraft": "收合編輯",
|
||||
"send": "送出訊息",
|
||||
"stop": "停止回覆",
|
||||
"quotedContext": "引用內容",
|
||||
|
||||
Reference in new issue
Block a user