Skip to content

Commit 429c625

Browse files
t3dotggclaude
andauthored
fix(web): workspace card docks beside chat when the window is narrow (#14992)
Chat stays centered while the workspace card fits beside it with 32px to spare. When it does not fit, chat moves left only as far as needed, narrows only after it reaches the left padding, and the card becomes a popover below a 640px chat. The card is lighter: 280px wide, 32px rows, no section labels, no "Project folder" hint. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 0cfa113 commit 429c625

14 files changed

Lines changed: 123 additions & 40 deletions

‎apps/web/src/components/BranchToolbarEnvModeSelector.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
5959
}: BranchToolbarEnvModeSelectorProps) {
6060
const workspacePath = displayMode === "panel" ? (activeWorktreePath ?? workspaceRoot) : null;
6161
const workspaceDisplayName = resolveWorkspaceDisplayName(workspacePath);
62-
const workspaceKind = activeWorktreePath ? "Worktree" : "Project folder";
62+
// The panel names the workspace kind only when it is not the project folder.
63+
const workspaceKind = activeWorktreePath ? "Worktree" : null;
64+
const lockedWorkspaceKind = forceNewWorktree ? "Worktree" : workspaceKind;
65+
const selectWorkspaceKind =
66+
effectiveEnvMode === "worktree" && !activeWorktreePath ? "Create" : workspaceKind;
6367
const composerFloatingLayerProps = useComposerMenuProps();
6468
const showPreviousWorktree = Boolean(previousWorktreeLabel && onUsePreviousWorktree);
6569
const envModeItems = useMemo(
@@ -147,9 +151,9 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
147151
: (workspaceDisplayName ??
148152
resolveLockedWorkspaceLabel(activeWorktreePath, effectiveEnvMode))}
149153
</ComposerContextLabel>
150-
{displayMode === "panel" ? (
154+
{displayMode === "panel" && lockedWorkspaceKind ? (
151155
<span className="shrink-0 text-3xs font-normal text-muted-foreground/70">
152-
{forceNewWorktree ? "Worktree" : workspaceKind}
156+
{lockedWorkspaceKind}
153157
</span>
154158
) : null}
155159
</span>
@@ -210,9 +214,9 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
210214
<ComposerContextLabel displayMode={displayMode}>
211215
<SelectValue />
212216
</ComposerContextLabel>
213-
{displayMode === "panel" ? (
217+
{displayMode === "panel" && selectWorkspaceKind ? (
214218
<span className="shrink-0 text-3xs font-normal text-muted-foreground/70">
215-
{effectiveEnvMode === "worktree" && !activeWorktreePath ? "Create" : workspaceKind}
219+
{selectWorkspaceKind}
216220
</span>
217221
) : null}
218222
</TooltipTrigger>

‎apps/web/src/components/GitActionsControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ export default function GitActionsControl({
18801880
// the output row expands below.
18811881
<GitActionElapsedTime
18821882
startedAtMs={gitActionProgress.startedAtMs}
1883-
className="flex h-9 shrink-0 items-center self-start pe-2.5 text-2xs font-normal tabular-nums text-muted-foreground"
1883+
className="flex h-8 shrink-0 items-center self-start pe-2.5 text-2xs font-normal tabular-nums text-muted-foreground"
18841884
/>
18851885
) : (
18861886
<>

‎apps/web/src/components/chat/ChatCanvas.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { ChatCanvasContext } from "./ChatCanvasContext";
1111
import { resolveChatCanvasLayout, type ChatCanvasPreview } from "./chatCanvasLayout";
1212
import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLayout";
1313

14-
/** Owns the available conversation space. Floating cards never reserve it themselves. */
14+
/**
15+
* Owns the available conversation space. Cards only report where they sit; the
16+
* canvas decides when chat moves over to make room for them.
17+
*/
1518
export function ChatCanvas({
1619
composerOverlayElement,
1720
children,
@@ -96,6 +99,7 @@ export function ChatCanvas({
9699
const container = { width: measurements.width, height: measurements.height };
97100
return {
98101
container,
102+
lane: { padding: measurements.padding, minChatWidth: measurements.minChatWidth },
99103
layout: resolveChatCanvasLayout({ ...measurements, container, preview, detailsCard }),
100104
previewKey: preview?.key ?? null,
101105
reportPreview,

‎apps/web/src/components/chat/ChatCanvasContext.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLay
44

55
export const ChatCanvasContext = createContext<{
66
container: { width: number; height: number };
7+
lane: { padding: number; minChatWidth: number };
78
layout: ReturnType<typeof resolveChatCanvasLayout>;
89
previewKey: string | null;
910
reportPreview: (preview: ChatCanvasPreview) => void;

‎apps/web/src/components/chat/ThreadDetailsCard.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ export function ThreadDetailsCard({
2929
const preferredPlacement = canvas
3030
? resolveThreadDetailsCardLayout({
3131
container: canvas.container,
32-
chat: canvas.layout.chat,
32+
lane: canvas.lane,
3333
frame: null,
3434
})
3535
: null;
3636
const placement = canvas
37-
? resolveThreadDetailsCardLayout({ container: canvas.container, ...canvas.layout })
37+
? resolveThreadDetailsCardLayout({
38+
container: canvas.container,
39+
lane: canvas.lane,
40+
frame: canvas.layout.frame,
41+
overlapsDetailsCard: canvas.layout.overlapsDetailsCard,
42+
})
3843
: null;
3944
const mode = placement ? "inline" : "popover";
4045
const inlineOpen = useRightPanelStore((state) =>

‎apps/web/src/components/chat/ThreadDetailsControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function ThreadDetailsControl({
5656
className: cn(
5757
"relative inline-flex shrink-0 cursor-pointer items-center whitespace-nowrap border outline-none transition-[box-shadow,scale] [&:active:not([aria-haspopup])]:scale-[0.97] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 disabled:pointer-events-none disabled:opacity-64 aria-disabled:cursor-not-allowed aria-disabled:opacity-64 [&_svg]:shrink-0",
5858
parts[part],
59-
multiline && "h-auto min-h-9 py-0.75 disabled:opacity-100 sm:h-auto",
59+
multiline && "h-auto min-h-8 py-0.75 disabled:opacity-100 sm:h-auto",
6060
tone === "muted" && "text-muted-foreground/70 hover:text-foreground/80",
6161
tone === "destructive" &&
6262
"text-destructive hover:text-destructive data-pressed:text-destructive",

‎apps/web/src/components/chat/ThreadDetailsPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
126126
headingId="thread-details-workspace-heading"
127127
title="Workspace"
128128
separated={false}
129-
showHeading={density === "full"}
129+
showHeading={false}
130130
>
131131
{props.versionMismatch ? (
132132
<div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
@@ -198,7 +198,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
198198
<ThreadDetailsSection
199199
headingId="thread-details-version-control-heading"
200200
title="Version Control"
201-
showHeading={density === "full"}
201+
showHeading={false}
202202
separated={density === "full"}
203203
>
204204
<div className="flex flex-col">

‎apps/web/src/components/chat/ThreadRelationshipsControl.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function ThreadLineageRowList(props: {
9797
<button
9898
type="button"
9999
onClick={props.onShowMore}
100-
className={`flex h-9 w-full cursor-pointer items-center rounded-lg ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-sm font-medium text-muted-foreground/70 hover:bg-black/[0.055] hover:text-foreground/80 dark:hover:bg-white/[0.075]`}
100+
className={`flex h-8 w-full cursor-pointer items-center rounded-lg ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-sm font-medium text-muted-foreground/70 hover:bg-black/[0.055] hover:text-foreground/80 dark:hover:bg-white/[0.075]`}
101101
>
102102
<PlusIcon aria-hidden className="size-4 shrink-0" />
103103
Show {Math.min(props.hiddenCount, THREAD_LINEAGE_PAGE_COUNT)} more
@@ -394,7 +394,7 @@ export function ThreadRelationshipsPanel(props: {
394394
</>
395395
);
396396
return (
397-
<li key={threadId} className="group flex h-9 items-center rounded-lg">
397+
<li key={threadId} className="group flex h-8 items-center rounded-lg">
398398
{isMergeTarget ? (
399399
<div className={THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS}>
400400
<Tooltip>

‎apps/web/src/components/chat/chatCanvasLayout.test.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ describe("chat canvas layout", () => {
212212
});
213213
};
214214
const density = (result: ReturnType<typeof layout>) => {
215-
const card = resolveThreadDetailsCardLayout({ container, ...result });
215+
const card = resolveThreadDetailsCardLayout({
216+
container,
217+
lane: { padding: 20, minChatWidth: 640 },
218+
frame: result.frame,
219+
overlapsDetailsCard: result.overlapsDetailsCard,
220+
});
216221
return card
217222
? resolveThreadDetailsCardDensity(card.height, { full: 327, compact: 182 })
218223
: "hidden";
@@ -251,3 +256,42 @@ describe("chat canvas layout", () => {
251256
expect(result.frame).toEqual({ x: 272, y: 396, width: 1300, height: 400 });
252257
});
253258
});
259+
260+
describe("workspace card beside chat", () => {
261+
const withCard = (width: number, player: ChatCanvasPreview | null = null, maxChatWidth = 736) =>
262+
resolveChatCanvasLayout({
263+
container: { width, height: 900 },
264+
maxChatWidth,
265+
composerHeight: 180,
266+
detailsCard: { left: width - 292, right: width - 12, bottom: 400 },
267+
preview: player,
268+
});
269+
it("keeps chat centered while the card fits beside it", () => {
270+
expect(withCard(1384).chat).toEqual({ left: 324, width: 736, insetStart: 0, insetEnd: 0 });
271+
});
272+
it("moves chat left only as far as the card requires", () => {
273+
expect(withCard(1383).chat).toEqual({ left: 323, width: 736, insetStart: 0, insetEnd: 1 });
274+
expect(withCard(1147).chat).toEqual({ left: 87, width: 736, insetStart: 0, insetEnd: 237 });
275+
});
276+
it("narrows chat only after it reaches the left padding", () => {
277+
expect(withCard(1080).chat).toMatchObject({ left: 20, width: 736 });
278+
expect(withCard(1000).chat).toEqual({ left: 20, width: 656, insetStart: 0, insetEnd: 304 });
279+
expect(withCard(984).chat).toMatchObject({ left: 20, width: 640 });
280+
});
281+
it("keeps a full-width chat clear of the card", () => {
282+
expect(withCard(1147, null, 10_000).chat).toEqual({
283+
left: 20,
284+
width: 803,
285+
insetStart: 0,
286+
insetEnd: 304,
287+
});
288+
});
289+
it("keeps centered chat in place when a new preview opens below the card", () => {
290+
expect(withCard(1440, preview)).toEqual({
291+
chat: { left: 352, width: 736, insetStart: 0, insetEnd: 0 },
292+
frame: { x: 1108, y: 688, width: 320, height: 200 },
293+
overlapsChat: false,
294+
overlapsDetailsCard: false,
295+
});
296+
});
297+
});

‎apps/web/src/components/chat/chatCanvasLayout.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ export interface ChatCanvasPreview {
1919
}
2020

2121
const GAP = 12;
22+
// Minimum space between chat and the workspace card. Chat stays centered while
23+
// the card fits beside it with this much room.
24+
export const DETAILS_CARD_CLEARANCE = 32;
2225

23-
/** Pure geometry shared by the conversation, composer, and floating preview. */
26+
/** Pure geometry shared by the conversation, composer, workspace card, and floating preview. */
2427
export function resolveChatCanvasLayout({
2528
container,
2629
preview,
@@ -38,9 +41,24 @@ export function resolveChatCanvasLayout({
3841
composerHeight?: number;
3942
detailsCard?: PreviewMiniPlayerObstacles["detailsCard"];
4043
}) {
41-
const normalWidth = Math.max(0, Math.min(maxChatWidth, container.width - padding * 2));
42-
const normalLeft = (container.width - normalWidth) / 2;
43-
let chat = { left: normalLeft, width: normalWidth, insetStart: 0, insetEnd: 0 };
44+
const centeredWidth = Math.max(0, Math.min(maxChatWidth, container.width - padding * 2));
45+
// A workspace card that does not fit beside the centered chat first moves
46+
// chat left, only as far as it needs. Chat narrows only after it reaches the
47+
// left padding.
48+
const laneRight = detailsCard
49+
? detailsCard.left - DETAILS_CARD_CLEARANCE
50+
: container.width - padding;
51+
const normalWidth = Math.max(0, Math.min(centeredWidth, laneRight - padding));
52+
const normalLeft = Math.max(
53+
padding,
54+
Math.min((container.width - normalWidth) / 2, laneRight - normalWidth),
55+
);
56+
let chat = {
57+
left: normalLeft,
58+
width: normalWidth,
59+
insetStart: 0,
60+
insetEnd: Math.max(0, container.width - normalLeft * 2 - normalWidth),
61+
};
4462
let frame: PreviewMiniPlayerFrame | null = null;
4563
let overlapsChat = false;
4664
if (preview && container.width > 0 && container.height > 0) {

0 commit comments

Comments
 (0)