Skip to content
TypeScript

feat(web): let users turn off composer collapse on blur and scroll (#9469)

Julius Marminge03728361aa7b
diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts
index 97f4ca85c50..28cce3cfb50 100644
--- a/apps/desktop/src/settings/DesktopClientSettings.test.ts
+++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts
@@ -28,6 +28,8 @@ const clientSettings: ClientSettings = {
confirmThreadUnpin: false,
continueThreadsAfterServerUpdate: true,
contextWindowMeterEnabled: false,
+ composerCollapseOnBlur: false,
+ composerCollapseOnScroll: true,
dismissedProviderUpdateNotificationKeys: [],
diffIgnoreWhitespace: true,
diffLayout: "stacked",
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index c38dd1cbe05..5f8376b431f 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -3542,8 +3542,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const isComposerResting = shouldUseRestingComposerLayout({
isExistingThread: routeKind === "server" && activeThreadId !== null,
isMobileViewport,
- isFocused: isComposerFocused && !isComposerScrollCollapsed,
+ isFocused: isComposerFocused,
+ isScrollCollapsed: isComposerScrollCollapsed,
hasExpandedChrome: composerHasExpandedChrome,
+ collapseOnBlur: settings.composerCollapseOnBlur,
});
// The relocated controls live in the context strip whenever the composer is
// collapsed for any reason, the desktop resting layout or the phone
@@ -3615,8 +3617,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const canTrackComposerScrollGesture =
routeKind === "server" && activeThreadId !== null && !isMobileViewport;
const canScrollCollapseComposer =
- canTrackComposerScrollGesture && !composerHasExpandedChrome && !showInlineTasksBadge;
- composerScrollCollapseEligibleRef.current = canScrollCollapseComposer;
+ canTrackComposerScrollGesture &&
+ settings.composerCollapseOnScroll &&
+ !composerHasExpandedChrome &&
+ !showInlineTasksBadge;
+ // Scrolling only has something to collapse while the composer is expanded.
+ // With blur collapse off that includes an unfocused composer, so the wheel
+ // handler keys off this rather than editor focus.
+ composerScrollCollapseEligibleRef.current = canScrollCollapseComposer && !isComposerResting;
useEffect(() => {
if (!canScrollCollapseComposer) {
@@ -3657,11 +3665,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
resetComposerScrollGesture(composerScrollGestureRef.current);
};
const handleTimelineWheel = (event: WheelEvent) => {
- const activeElement = document.activeElement;
- const isPromptEditorFocused =
- activeElement instanceof HTMLElement &&
- activeElement.isContentEditable &&
- composerFormRef.current?.contains(activeElement) === true;
if (event.ctrlKey || !(event.target instanceof Element)) {
return;
}
@@ -3695,8 +3698,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
now: window.performance.now(),
deltaPx,
collapseThresholdPx: COMPOSER_SCROLL_COLLAPSE_THRESHOLD_PX,
- collapseEligible:
- targetsTimeline && composerScrollCollapseEligibleRef.current && isPromptEditorFocused,
+ collapseEligible: targetsTimeline && composerScrollCollapseEligibleRef.current,
canScrollInGestureDirection,
scrollsTowardLogicalEnd: event.deltaY > 0 && isTimelineAtLogicalEnd(),
});
diff --git a/apps/web/src/components/composerFooterLayout.test.ts b/apps/web/src/components/composerFooterLayout.test.ts
index 926816508ec..ea2a1de2064 100644
--- a/apps/web/src/components/composerFooterLayout.test.ts
+++ b/apps/web/src/components/composerFooterLayout.test.ts
@@ -79,13 +79,36 @@ describe("shouldUseRestingComposerLayout", () => {
isExistingThread: true,
isMobileViewport: false,
isFocused: false,
+ isScrollCollapsed: false,
hasExpandedChrome: false,
+ collapseOnBlur: true,
};
it("uses the resting layout for an unfocused desktop composer", () => {
expect(shouldUseRestingComposerLayout(resting)).toBe(true);
});
+ it("keeps an unfocused composer expanded when blur collapse is off", () => {
+ expect(shouldUseRestingComposerLayout({ ...resting, collapseOnBlur: false })).toBe(false);
+ });
+
+ it("rests a scroll-collapsed composer even while focused", () => {
+ expect(
+ shouldUseRestingComposerLayout({ ...resting, isFocused: true, isScrollCollapsed: true }),
+ ).toBe(true);
+ });
+
+ it("rests a scroll-collapsed composer regardless of the blur preference", () => {
+ expect(
+ shouldUseRestingComposerLayout({
+ ...resting,
+ isFocused: true,
+ isScrollCollapsed: true,
+ collapseOnBlur: false,
+ }),
+ ).toBe(true);
+ });
+
it("keeps new-thread composers expanded", () => {
expect(shouldUseRestingComposerLayout({ ...resting, isExistingThread: false })).toBe(false);
});
diff --git a/apps/web/src/components/composerFooterLayout.ts b/apps/web/src/components/composerFooterLayout.ts
index 2ab3b36a1b9..56a9d43de99 100644
--- a/apps/web/src/components/composerFooterLayout.ts
+++ b/apps/web/src/components/composerFooterLayout.ts
@@ -27,7 +27,9 @@ export function shouldUseRestingComposerLayout(input: {
isExistingThread: boolean;
isMobileViewport: boolean;
isFocused: boolean;
+ isScrollCollapsed: boolean;
hasExpandedChrome: boolean;
+ collapseOnBlur: boolean;
}): boolean {
// Passive draft content is deliberately absent here. Resting only clamps
// the prompt row and overlays its actions; non-image attachment and context
@@ -37,12 +39,13 @@ export function shouldUseRestingComposerLayout(input: {
// deliberately absent here: resting reclaims vertical space at every
// desktop width, and where the strip is missing or too narrow the controls
// simply return when the composer is focused.
- return (
- input.isExistingThread &&
- !input.isMobileViewport &&
- !input.isFocused &&
- !input.hasExpandedChrome
- );
+ //
+ // A scroll collapse rests the composer regardless of the blur preference:
+ // the user asked for it with the gesture, and it lifts on the next
+ // composer interaction. With blur collapse off, losing focus alone never
+ // rests the composer.
+ const collapsed = input.isScrollCollapsed || (input.collapseOnBlur && !input.isFocused);
+ return input.isExistingThread && !input.isMobileViewport && collapsed && !input.hasExpandedChrome;
}
export function shouldAnimateComposerRestingTransition(input: {
diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx
index 35985f57a1f..6ee1b7e2d0d 100644
--- a/apps/web/src/components/settings/SettingsPanels.tsx
+++ b/apps/web/src/components/settings/SettingsPanels.tsx
@@ -172,6 +172,12 @@ const TIMESTAMP_FORMAT_LABELS = {
"24-hour": "24-hour",
} as const;
+const COMPOSER_COLLAPSE_TRIGGER_LABELS = {
+ blur: "On unfocus",
+ scroll: "On scroll",
+} as const;
+type ComposerCollapseTrigger = keyof typeof COMPOSER_COLLAPSE_TRIGGER_LABELS;
+
const DIFF_LAYOUT_LABELS: Record<DiffLayout, string> = {
stacked: "Stacked",
split: "Split",
@@ -542,6 +548,10 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.showSkillsInSlashMenu !== DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu
? ["Show skills in slash menu"]
: []),
+ ...(settings.composerCollapseOnBlur !== DEFAULT_UNIFIED_SETTINGS.composerCollapseOnBlur ||
+ settings.composerCollapseOnScroll !== DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll
+ ? ["Collapse composer"]
+ : []),
...(settings.contextWindowMeterEnabled !== DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled
? ["Context window indicator"]
: []),
@@ -599,6 +609,8 @@ export function useSettingsRestore(onRestored?: () => void) {
settings.confirmThreadArchive,
settings.confirmThreadDelete,
settings.confirmThreadUnpin,
+ settings.composerCollapseOnBlur,
+ settings.composerCollapseOnScroll,
settings.addProjectBaseDirectory,
settings.defaultThreadEnvMode,
settings.newWorktreesStartFromOrigin,
@@ -703,6 +715,8 @@ export function useSettingsRestore(onRestored?: () => void) {
diffLayout: DEFAULT_UNIFIED_SETTINGS.diffLayout,
proactivePanelsEnabled: DEFAULT_UNIFIED_SETTINGS.proactivePanelsEnabled,
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
+ composerCollapseOnBlur: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnBlur,
+ composerCollapseOnScroll: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll,
contextWindowMeterEnabled: DEFAULT_UNIFIED_SETTINGS.contextWindowMeterEnabled,
environmentIdentificationMode: DEFAULT_UNIFIED_SETTINGS.environmentIdentificationMode,
glassOpacity: DEFAULT_UNIFIED_SETTINGS.glassOpacity,
@@ -2010,6 +2024,13 @@ export function GeneralSettingsPanel() {
const serverProviders = useAtomValue(primaryServerProvidersAtom);
const supportsAutoSettlement =
useAtomValue(primaryServerConfigAtom)?.environment.capabilities.threadAutoSettlement === true;
+ const composerCollapseTriggers = useMemo<ComposerCollapseTrigger[]>(
+ () => [
+ ...(settings.composerCollapseOnBlur ? (["blur"] as const) : []),
+ ...(settings.composerCollapseOnScroll ? (["scroll"] as const) : []),
+ ],
+ [settings.composerCollapseOnBlur, settings.composerCollapseOnScroll],
+ );
const diagnosticsDescription = formatDiagnosticsDescription({
localTracingEnabled: observability?.localTracingEnabled ?? false,
otlpTracesEnabled: observability?.otlpTracesEnabled ?? false,
@@ -2334,6 +2355,56 @@ export function GeneralSettingsPanel() {
}
/>
+ <SettingsRow
+ {...searchableSetting("composer-collapse")}
+ description="Rest the composer of an existing thread into a single line when it loses focus, when you scroll the conversation, or both. Pick neither to keep it expanded."
+ resetAction={
+ settings.composerCollapseOnBlur !== DEFAULT_UNIFIED_SETTINGS.composerCollapseOnBlur ||
+ settings.composerCollapseOnScroll !==
+ DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll ? (
+ <SettingResetButton
+ label="collapse composer"
+ onClick={() =>
+ updateSettings({
+ composerCollapseOnBlur: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnBlur,
+ composerCollapseOnScroll: DEFAULT_UNIFIED_SETTINGS.composerCollapseOnScroll,
+ })
+ }
+ />
+ ) : null
+ }
+ control={
+ <Select
+ multiple
+ value={composerCollapseTriggers}
+ onValueChange={(next) =>
+ updateSettings({
+ composerCollapseOnBlur: next.includes("blur"),
+ composerCollapseOnScroll: next.includes("scroll"),
+ })
+ }
+ >
+ <SelectTrigger size="sm" className="w-full sm:w-40" aria-label="Collapse composer">
+ <SelectValue>
+ {composerCollapseTriggers.length === 0
+ ? "Never"
+ : composerCollapseTriggers
+ .map((trigger) => COMPOSER_COLLAPSE_TRIGGER_LABELS[trigger])
+ .join(", ")}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectPopup align="end" alignItemWithTrigger={false}>
+ <SelectItem showCheck value="blur">
+ {COMPOSER_COLLAPSE_TRIGGER_LABELS.blur}
+ </SelectItem>
+ <SelectItem showCheck value="scroll">
+ {COMPOSER_COLLAPSE_TRIGGER_LABELS.scroll}
+ </SelectItem>
+ </SelectPopup>
+ </Select>
+ }
+ />
+
<SettingsRow
serverScoped
{...searchableSetting("provider-update-checks")}
diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts
index 47ec0f693b9..78b90890c9b 100644
--- a/apps/web/src/components/settings/settingsSearch.ts
+++ b/apps/web/src/components/settings/settingsSearch.ts
@@ -202,6 +202,14 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/general",
searchTerms: ["command menu dollar $ slash /"],
},
+ {
+ id: "composer-collapse",
+ title: "Collapse composer",
+ to: "/settings/general",
+ searchTerms: [
+ "composer rest resting unfocus blur focus click away scroll wheel conversation timeline shrink minimize",
+ ],
+ },
{
id: "provider-update-checks",
title: "Provider update checks",
diff --git a/apps/web/src/components/ui/select.tsx b/apps/web/src/components/ui/select.tsx
index 46b2c8eb1ba..22f5b5763f6 100644
--- a/apps/web/src/components/ui/select.tsx
+++ b/apps/web/src/components/ui/select.tsx
@@ -4,7 +4,7 @@ import { mergeProps } from "@base-ui/react/merge-props";
import { Select as SelectPrimitive } from "@base-ui/react/select";
import { useRender } from "@base-ui/react/use-render";
import { cva, type VariantProps } from "class-variance-authority";
-import { ChevronDownIcon, ChevronsUpDownIcon, ChevronUpIcon } from "lucide-react";
+import { CheckIcon, ChevronDownIcon, ChevronsUpDownIcon, ChevronUpIcon } from "lucide-react";
import type * as React from "react";
import { cn } from "~/lib/utils";
@@ -180,19 +180,32 @@ function SelectItem({
className,
children,
hideIndicator: _hideIndicator = false,
+ showCheck = false,
...props
}: SelectPrimitive.Item.Props & {
hideIndicator?: boolean;
+ /** Render a check mark on selected items. Multi-selects use it so every chosen item is visible at once. */
+ showCheck?: boolean;
}) {
return (
<SelectPrimitive.Item
className={cn(
"flex min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-pointer items-center rounded-sm px-2 py-1 text-base outline-none data-selected:bg-foreground/[0.08] data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
+ showCheck && "gap-2",
className,
)}
data-slot="select-item"
{...props}
>
+ {showCheck ? (
+ <SelectPrimitive.ItemIndicator
+ className="flex w-4 shrink-0 items-center justify-center"
+ data-slot="select-item-indicator"
+ keepMounted
+ >
+ <CheckIcon className="in-data-[selected]:opacity-100 opacity-0" />
+ </SelectPrimitive.ItemIndicator>
+ ) : null}
<SelectPrimitive.ItemText
className="min-w-0 flex-1 [&_svg:not([class*='text-'])]:text-muted-foreground"
data-slot="select-item-text"
diff --git a/docs/user/composer.md b/docs/user/composer.md
index 9ef7f883765..1affd1631ca 100644
--- a/docs/user/composer.md
+++ b/docs/user/composer.md
@@ -56,7 +56,8 @@ the composer loses focus. At wider sizes, scrolling the conversation also rests
except when scrolling toward the end while already there. When the thread-context strip has room,
the model and mode controls stay available beside the thread context; otherwise they return when the
composer is focused. Focus the composer or start typing to expand it again. New-thread layouts keep
-the full composer.
+the full composer. **Settings → General → Collapse composer** chooses which triggers rest it:
+**On unfocus**, **On scroll**, both, or neither. With neither selected the composer stays expanded.
At phone-sized web or desktop window widths, existing threads animate between their compact and
expanded layouts. Up to three image attachments remain visible in either resting layout, followed
diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts
index 61ad3be4109..5d4c1573ef7 100644
--- a/packages/contracts/src/settings.test.ts
+++ b/packages/contracts/src/settings.test.ts
@@ -228,6 +228,22 @@ describe("ClientSettings context window meter", () => {
});
});
+describe("ClientSettings composer collapse", () => {
+ it("collapses on blur and scroll by default and accepts opting out of each", () => {
+ const defaults = decodeClientSettings({});
+ expect(defaults.composerCollapseOnBlur).toBe(true);
+ expect(defaults.composerCollapseOnScroll).toBe(true);
+
+ const blurOff = decodeClientSettings({ composerCollapseOnBlur: false });
+ expect(blurOff.composerCollapseOnBlur).toBe(false);
+ expect(blurOff.composerCollapseOnScroll).toBe(true);
+
+ expect(
+ decodeClientSettingsPatch({ composerCollapseOnScroll: false }).composerCollapseOnScroll,
+ ).toBe(false);
+ });
+});
+
describe("ServerSettings thread settlement", () => {
it("defaults merge settlement on and inactivity settlement to three days", () => {
const settings = decodeServerSettings({});
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index 9f1f0c846ac..c1ee59e948d 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -319,6 +319,10 @@ export const ClientSettingsSchema = Schema.Struct({
// Legacy context window meter. The composer hides it by default; users who
// still want the old usage indicator can restore it from Settings.
contextWindowMeterEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
+ // Desktop resting composer. Each trigger that settles an existing thread's
+ // composer into its single-line layout can be turned off on its own.
+ composerCollapseOnBlur: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
+ composerCollapseOnScroll: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
proactivePanelsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
showSkillsInSlashMenu: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
// Legacy sidebar (the original per-project tree). Deliberately a fresh key
@@ -1165,6 +1169,8 @@ export const ClientSettingsPatch = Schema.Struct({
),
planModeEnabled: Schema.optionalKey(Schema.Boolean),
contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),
+ composerCollapseOnBlur: Schema.optionalKey(Schema.Boolean),
+ composerCollapseOnScroll: Schema.optionalKey(Schema.Boolean),
proactivePanelsEnabled: Schema.optionalKey(Schema.Boolean),
showSkillsInSlashMenu: Schema.optionalKey(Schema.Boolean),
legacySidebarEnabled: Schema.optionalKey(Schema.Boolean),