@@ -12,7 +12,6 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat
1212import { useComposerDraftStore , type DraftId } from "../composerDraftStore" ;
1313import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon" ;
1414import { useProject , useThread , useThreadShellsForProjectRefs } from "../state/entities" ;
15- import { useIsMobile } from "../hooks/useMediaQuery" ;
1615import {
1716 type EnvMode ,
1817 type EnvironmentOption ,
@@ -40,6 +39,7 @@ import {
4039} from "./ui/menu" ;
4140import { Separator } from "./ui/separator" ;
4241import { ComposerSurface } from "./chat/ComposerSurface" ;
42+ import { cn } from "~/lib/utils" ;
4343
4444interface BranchToolbarProps {
4545 environmentId : EnvironmentId ;
@@ -57,6 +57,8 @@ interface BranchToolbarProps {
5757 onComposerFocusRequest ?: ( ) => void ;
5858 availableEnvironments ?: readonly EnvironmentOption [ ] ;
5959 onEnvironmentChange ?: ( environmentId : EnvironmentId ) => void ;
60+ composerControlsHostRef ?: ( element : HTMLDivElement | null ) => void ;
61+ contextStripVisible ?: boolean ;
6062}
6163
6264interface MobileRunContextSelectorProps {
@@ -120,15 +122,26 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
120122 const triggerContent = (
121123 < >
122124 { icon }
123- < span className = "min-w-0 truncate" >
124- { showEnvironmentIndicator ? ( activeEnvironment ?. label ?? "Run on" ) : workspaceLabel }
125+ < span
126+ data-composer-label
127+ className = "min-w-0 max-w-[240px] group-data-[compact]/composer-context:max-w-0"
128+ >
129+ < span
130+ data-composer-label-motion
131+ className = "block w-full min-w-0 max-w-[240px] origin-left truncate transition-[opacity,transform] duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:[transform:translateX(-0.25rem)_scaleX(0.95)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transform-none motion-reduce:transition-opacity"
132+ >
133+ { showEnvironmentIndicator ? ( activeEnvironment ?. label ?? "Run on" ) : workspaceLabel }
134+ </ span >
125135 </ span >
126136 </ >
127137 ) ;
128138
129139 if ( isLocked ) {
130140 return (
131- < span className = "inline-flex h-7 min-w-0 max-w-[48%] flex-1 items-center justify-start gap-1 rounded-md border border-transparent px-[calc(--spacing(2)-1px)] text-sm font-medium text-muted-foreground/70 sm:h-6 md:hidden" >
141+ < span
142+ className = "inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
143+ data-composer-context-control
144+ >
132145 { triggerContent }
133146 </ span >
134147 ) ;
@@ -138,7 +151,8 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
138151 < Menu >
139152 < MenuTrigger
140153 render = { < Button variant = "ghost" size = "xs" /> }
141- className = "min-w-0 max-w-[48%] flex-1 justify-start text-muted-foreground/70 hover:text-foreground/80 md:hidden"
154+ className = "min-w-0 max-w-[48%] flex-initial justify-start font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80"
155+ data-composer-context-control
142156 >
143157 { triggerContent }
144158 < ChevronDownIcon className = "size-3 shrink-0 opacity-50" />
@@ -251,10 +265,14 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
251265 let counted = 0 ;
252266 for ( const child of parent . children ) {
253267 if ( ! ( child instanceof HTMLElement ) ) continue ;
254- if ( child . offsetWidth <= 1 ) continue ;
255- const position = getComputedStyle ( child ) . position ;
268+ if ( child . offsetWidth === 0 ) continue ;
269+ const style = getComputedStyle ( child ) ;
270+ const position = style . position ;
256271 if ( position === "absolute" || position === "fixed" ) continue ;
257- width += child . offsetWidth ;
272+ width +=
273+ child . offsetWidth +
274+ ( Number . parseFloat ( style . marginInlineStart ) || 0 ) +
275+ ( Number . parseFloat ( style . marginInlineEnd ) || 0 ) ;
258276 counted += 1 ;
259277 }
260278 return width + gap * Math . max ( 0 , counted - 1 ) ;
@@ -264,10 +282,15 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
264282 let groups = 0 ;
265283 for ( const child of current . children ) {
266284 if ( ! ( child instanceof HTMLElement ) ) continue ;
267- const width = contentWidth ( child ) ;
285+ // The host itself flexes into all remaining room. Measure the controls
286+ // inside it so Git labels compact before squeezing out the model picker.
287+ const hostedControls = child . matches ( '[data-chat-resting-composer-controls-host="true"]' )
288+ ? child . querySelector < HTMLElement > ( '[data-chat-composer-resting-controls="true"]' )
289+ : null ;
290+ const width = hostedControls ? contentWidth ( hostedControls ) : contentWidth ( child ) ;
268291 if ( width <= 1 ) continue ;
269- needed += width ;
270292 groups += 1 ;
293+ needed += width ;
271294 }
272295 needed += stripGap * Math . max ( 0 , groups - 1 ) ;
273296 for ( const label of current . querySelectorAll < HTMLElement > ( "[data-composer-label]" ) ) {
@@ -390,6 +413,8 @@ export const BranchToolbar = memo(function BranchToolbar({
390413 onComposerFocusRequest,
391414 availableEnvironments,
392415 onEnvironmentChange,
416+ composerControlsHostRef,
417+ contextStripVisible = true ,
393418} : BranchToolbarProps ) {
394419 const threadRef = useMemo (
395420 ( ) => scopeThreadRef ( environmentId , threadId ) ,
@@ -460,7 +485,6 @@ export const BranchToolbar = memo(function BranchToolbar({
460485 activeEnvironment : activeEnvironmentOption ,
461486 canPickEnvironment : showEnvironmentPicker ,
462487 } ) ;
463- const isMobile = useIsMobile ( ) ;
464488 const [ stripElement , setStripElement ] = useState < HTMLDivElement | null > ( null ) ;
465489 const labelsOverflow = useLabelsOverflow ( stripElement ) ;
466490
@@ -470,24 +494,40 @@ export const BranchToolbar = memo(function BranchToolbar({
470494 < ComposerSurface . ContextStrip
471495 ref = { setStripElement }
472496 data-compact = { labelsOverflow ? "" : undefined }
497+ className = { cn (
498+ "gap-1 text-xs font-normal text-muted-foreground/70" ,
499+ // A non-Git strip with no visible composer controls should occupy no
500+ // space, but its host must retain a prospective width so controls can
501+ // become visible again when the chat view grows.
502+ ! contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full" ,
503+ ) }
473504 >
474- { isMobile && showGitControls ? (
475- < MobileRunContextSelector
476- envLocked = { envLocked }
477- envModeLocked = { envModeLocked }
478- environmentId = { environmentId }
479- availableEnvironments = { availableEnvironments }
480- showEnvironmentPicker = { showEnvironmentPicker }
481- showEnvironmentIndicator = { showEnvironmentIndicator }
482- onEnvironmentChange = { onEnvironmentChange }
483- effectiveEnvMode = { effectiveEnvMode }
484- activeWorktreePath = { activeWorktreePath }
485- onEnvModeChange = { onEnvModeChange }
486- previousWorktreeLabel = { previousWorktreeLabel }
487- onUsePreviousWorktree = { onUsePreviousWorktree }
488- />
489- ) : (
490- < div className = "flex min-w-10 flex-1 items-center gap-1" >
505+ { showGitControls ? (
506+ < div className = "contents @3xl/composer-surface:hidden" >
507+ < MobileRunContextSelector
508+ envLocked = { envLocked }
509+ envModeLocked = { envModeLocked }
510+ environmentId = { environmentId }
511+ availableEnvironments = { availableEnvironments }
512+ showEnvironmentPicker = { showEnvironmentPicker }
513+ showEnvironmentIndicator = { showEnvironmentIndicator }
514+ onEnvironmentChange = { onEnvironmentChange }
515+ effectiveEnvMode = { effectiveEnvMode }
516+ activeWorktreePath = { activeWorktreePath }
517+ onEnvModeChange = { onEnvModeChange }
518+ previousWorktreeLabel = { previousWorktreeLabel }
519+ onUsePreviousWorktree = { onUsePreviousWorktree }
520+ />
521+ </ div >
522+ ) : null }
523+ { showGitControls || showEnvironmentIndicator ? (
524+ < div
525+ className = { cn (
526+ "min-h-7 min-w-10 items-center gap-1 sm:min-h-6" ,
527+ showGitControls ? "hidden @3xl/composer-surface:flex" : "flex" ,
528+ composerControlsHostRef ? "shrink" : "flex-1" ,
529+ ) }
530+ >
491531 { showEnvironmentIndicator && availableEnvironments && (
492532 < >
493533 < BranchToolbarEnvironmentSelector
@@ -516,11 +556,23 @@ export const BranchToolbar = memo(function BranchToolbar({
516556 />
517557 ) : null }
518558 </ div >
519- ) }
559+ ) : null }
560+
561+ { composerControlsHostRef ? (
562+ // The host takes whatever the workspace and branch controls leave
563+ // over, in both strip layouts, so a collapsed composer can show its
564+ // model and mode controls wherever they fit.
565+ < div
566+ ref = { composerControlsHostRef }
567+ data-composer-context-control
568+ data-chat-resting-composer-controls-host = "true"
569+ className = "flex min-w-0 flex-1 items-center justify-start overflow-x-clip overflow-y-visible"
570+ />
571+ ) : null }
520572
521573 { showGitControls ? (
522574 < BranchToolbarBranchSelector
523- className = "min-w-0 flex-1 justify-end md :ml-auto md:flex-initial "
575+ className = "min-w-0 flex-initial justify-end @3xl/composer-surface :ml-auto"
524576 environmentId = { environmentId }
525577 threadId = { threadId }
526578 { ...( draftId ? { draftId } : { } ) }
0 commit comments