Skip to content

Commit 7960f42

Browse files
t3dotggclaude
andcommitted
fix(web): chat stays centered unless the workspace card needs room
Re-centering chat in the space beside a docked card put it far off center at common widths. Chat now stays centered while the 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. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 301a5d1 commit 7960f42

6 files changed

Lines changed: 44 additions & 74 deletions

File tree

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
type CSSProperties,
99
} from "react";
1010
import { ChatCanvasContext } from "./ChatCanvasContext";
11-
import {
12-
resolveChatCanvasLayout,
13-
resolveDockedChatMargin,
14-
type ChatCanvasPreview,
15-
} from "./chatCanvasLayout";
11+
import { resolveChatCanvasLayout, type ChatCanvasPreview } from "./chatCanvasLayout";
1612
import type { PreviewMiniPlayerObstacles } from "../preview/previewMiniPlayerLayout";
1713

1814
/**
@@ -103,10 +99,7 @@ export function ChatCanvas({
10399
const container = { width: measurements.width, height: measurements.height };
104100
return {
105101
container,
106-
lane: {
107-
margin: resolveDockedChatMargin(measurements),
108-
minChatWidth: measurements.minChatWidth,
109-
},
102+
lane: { padding: measurements.padding, minChatWidth: measurements.minChatWidth },
110103
layout: resolveChatCanvasLayout({ ...measurements, container, preview, detailsCard }),
111104
previewKey: preview?.key ?? null,
112105
reportPreview,

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

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

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

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe("chat canvas layout", () => {
214214
const density = (result: ReturnType<typeof layout>) => {
215215
const card = resolveThreadDetailsCardLayout({
216216
container,
217-
lane: { margin: 96, minChatWidth: 640 },
217+
lane: { padding: 20, minChatWidth: 640 },
218218
frame: result.frame,
219219
overlapsDetailsCard: result.overlapsDetailsCard,
220220
});
@@ -257,7 +257,7 @@ describe("chat canvas layout", () => {
257257
});
258258
});
259259

260-
describe("workspace card docking", () => {
260+
describe("workspace card beside chat", () => {
261261
const withCard = (width: number, player: ChatCanvasPreview | null = null, maxChatWidth = 736) =>
262262
resolveChatCanvasLayout({
263263
container: { width, height: 900 },
@@ -266,34 +266,30 @@ describe("workspace card docking", () => {
266266
detailsCard: { left: width - 292, right: width - 12, bottom: 400 },
267267
preview: player,
268268
});
269-
it("floats the card while the centered chat stays clear of it", () => {
270-
expect(withCard(1512).chat).toEqual({ left: 388, width: 736, insetStart: 0, insetEnd: 0 });
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 });
271271
});
272-
it("docks the card and centers chat beside it once the margin is tight", () => {
273-
expect(withCard(1511).chat).toEqual({
274-
left: 241.5,
275-
width: 736,
276-
insetStart: 76,
277-
insetEnd: 368,
278-
});
279-
expect(withCard(1411).chat).toMatchObject({ left: 191.5, width: 736 });
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 });
280275
});
281-
it("narrows docked chat before giving up the space beside it", () => {
282-
expect(withCard(1147).chat).toEqual({ left: 96, width: 663, insetStart: 76, insetEnd: 368 });
283-
expect(withCard(1124).chat).toMatchObject({ left: 96, width: 640 });
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 });
284280
});
285-
it("keeps a full-width chat at its normal padding beside the card", () => {
281+
it("keeps a full-width chat clear of the card", () => {
286282
expect(withCard(1147, null, 10_000).chat).toEqual({
287283
left: 20,
288-
width: 815,
284+
width: 803,
289285
insetStart: 0,
290-
insetEnd: 292,
286+
insetEnd: 304,
291287
});
292288
});
293-
it("keeps docked chat in place when a new preview opens below the card", () => {
294-
expect(withCard(1411, preview)).toEqual({
295-
chat: { left: 191.5, width: 736, insetStart: 76, insetEnd: 368 },
296-
frame: { x: 1079, y: 688, width: 320, height: 200 },
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 },
297293
overlapsChat: false,
298294
overlapsDetailsCard: false,
299295
});

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

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,9 @@ export interface ChatCanvasPreview {
1919
}
2020

2121
const GAP = 12;
22-
// Space between chat and the workspace card. The card floats in the right
23-
// margin while the centered chat clears it by this much. Closer than this, the
24-
// card docks and chat keeps this space on both sides.
25-
const DETAILS_CARD_CLEARANCE = 96;
26-
27-
/**
28-
* Space on each side of chat while the workspace card is docked. Chat gives up
29-
* width before this space. It never exceeds the centered margin, so a
30-
* full-width chat stays full width.
31-
*/
32-
export function resolveDockedChatMargin({
33-
width,
34-
padding,
35-
maxChatWidth,
36-
}: {
37-
width: number;
38-
padding: number;
39-
maxChatWidth: number;
40-
}) {
41-
const centeredWidth = Math.max(0, Math.min(maxChatWidth, width - padding * 2));
42-
return Math.min(DETAILS_CARD_CLEARANCE, (width - centeredWidth) / 2);
43-
}
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;
4425

4526
/** Pure geometry shared by the conversation, composer, workspace card, and floating preview. */
4627
export function resolveChatCanvasLayout({
@@ -61,23 +42,22 @@ export function resolveChatCanvasLayout({
6142
detailsCard?: PreviewMiniPlayerObstacles["detailsCard"];
6243
}) {
6344
const centeredWidth = Math.max(0, Math.min(maxChatWidth, container.width - padding * 2));
64-
// Without that clearance the card docks like a sidebar, and chat centers in
65-
// the space to its left.
66-
const docked =
67-
detailsCard !== null &&
68-
(container.width + centeredWidth) / 2 + DETAILS_CARD_CLEARANCE > detailsCard.left;
69-
const laneRight = docked ? detailsCard.left : container.width;
70-
const margin = docked
71-
? resolveDockedChatMargin({ width: container.width, padding, maxChatWidth })
72-
: padding;
73-
const normalWidth = Math.max(0, Math.min(maxChatWidth, laneRight - margin * 2));
74-
const normalLeft = (laneRight - normalWidth) / 2;
75-
// The lane CSS adds `padding` on each side, so the insets carry the rest.
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+
);
7656
let chat = {
7757
left: normalLeft,
7858
width: normalWidth,
79-
insetStart: margin - padding,
80-
insetEnd: container.width - laneRight + margin - padding,
59+
insetStart: 0,
60+
insetEnd: Math.max(0, container.width - normalLeft * 2 - normalWidth),
8161
};
8262
let frame: PreviewMiniPlayerFrame | null = null;
8363
let overlapsChat = false;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
resolveThreadDetailsCardLayout,
55
} from "./threadDetailsCardLayout";
66

7-
const lane = { margin: 96, minChatWidth: 640 };
7+
const lane = { padding: 20, minChatWidth: 640 };
88
const resolve = (width: number, height: number, previewY: number | null = null) =>
99
resolveThreadDetailsCardLayout({
1010
container: { width, height },
@@ -22,9 +22,9 @@ describe("workspace card", () => {
2222
});
2323
expect(resolve(1344, 900)).toMatchObject({ x: 1052, width: 280 });
2424
});
25-
it("hides when a readable chat lane and its margins cannot fit beside it", () => {
26-
expect(resolve(1124, 900)).toMatchObject({ x: 832 });
27-
expect(resolve(1123, 900)).toBeNull();
25+
it("hides when a readable chat lane cannot fit beside it", () => {
26+
expect(resolve(984, 900)).toMatchObject({ x: 692 });
27+
expect(resolve(983, 900)).toBeNull();
2828
});
2929
it("keeps the card at the top right while the preview is freely dragged vertically", () => {
3030
for (const y of [12, 170, 250, 400, 648]) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2+
import { DETAILS_CARD_CLEARANCE } from "./chatCanvasLayout";
23

34
export function resolveThreadDetailsCardDensity(
45
height: number,
@@ -20,15 +21,15 @@ export function resolveThreadDetailsCardLayout({
2021
overlapsDetailsCard = false,
2122
}: {
2223
container: { width: number; height: number };
23-
lane: { margin: number; minChatWidth: number };
24+
lane: { padding: number; minChatWidth: number };
2425
frame: PreviewMiniPlayerFrame | null;
2526
overlapsDetailsCard?: boolean;
2627
}) {
2728
const gap = 12;
2829
// Keep in sync with --thread-details-panel-width, which sizes the popover.
2930
const width = 280;
3031
const x = container.width - width - gap;
31-
if (x - lane.margin * 2 < lane.minChatWidth) return null;
32+
if (x - DETAILS_CARD_CLEARANCE - lane.padding < lane.minChatWidth) return null;
3233
// Resizing consumes the height above the player. Dragging first tries to
3334
// clear the full card and folds it only when there is no readable placement.
3435
const height =

0 commit comments

Comments
 (0)