Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 新建对话框留出左右呼吸空间,不再顶满全宽 (#342)

zhangyongjiefdb3a1e206e3
diff --git a/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts b/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts
index 4511d143b4..af5b1e0c3e 100644
--- a/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts
+++ b/apps/desktop/src/renderer/__tests__/newMakerCreateAgentVisualContract.test.ts
@@ -57,7 +57,7 @@ describe('NewMakerDraftRoute CREATE AGENT visual contract', () => {
expect(source).toContain('pt-[calc(max(96px,28vh)_+_46px_-_var(--content-header-h,46px))]');
expect(source).not.toContain('pt-[clamp(96px,25.5vh,268px)]');
// 内容列宽度从死锁 800px 改为跟随 useProportionalWidth 的 inputWidth(与进行中
- // 对话页同源,封顶 1220px):大屏自适应变宽、发送后同一 ChatInput 无宽度跳变。
+ // 对话页同源,封顶 914+20=934px):大屏留出左右呼吸空间、发送后同一 ChatInput 无宽度跳变。
expect(source).toContain('relative flex w-full flex-col items-start');
expect(source).toContain('style={{ maxWidth: inputWidth || 800 }}');
expect(source).not.toContain('max-w-[800px]');
diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
index 0c209243e1..e736ac7322 100644
--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
@@ -327,8 +327,10 @@ export function NewMakerDraftRoute() {
const { t } = useTranslation();
const draft = useNewMakerDraft();
const navigate = useNavigate();
- // minWidth=640:自适应内容列在大屏封顶 1220(hook 内 MAX),小屏兜一个体面下限
- // (与对话页的 max 对称);窄于下限时 hook 自动回落成"填满容器",不溢出。
+ // 首参 914=内容封顶宽(→ inputWidth 封顶 934):大屏留出左右呼吸空间,不再顶满全宽;
+ // 与进行中对话页(CCAgentSessionView 同传 914)一致,发送首条消息时输入框宽度不跳变。
+ // minWidth=640:小屏兜一个体面下限(与对话页对称);窄于下限时 hook 自动回落成
+ // "填满容器",不溢出。
const { containerRef, inputWidth } = useProportionalWidth(914, { minWidth: 640 });
// The available rail can shrink when either sidebar opens while the
// viewport itself remains wide. Keep the draft layout responsive to that
@@ -2074,8 +2076,9 @@ export function NewMakerDraftRoute() {
<div
className="relative flex w-full flex-col items-start"
// 与进行中对话页同源:内容列宽度跟随 useProportionalWidth 算出的
- // inputWidth(封顶 1220px),不再死锁 800——大屏自适应变宽,且发送后
- // 同一个 ChatInput 无宽度跳变。inputWidth 由 useLayoutEffect 同步量出
+ // inputWidth(封顶 914+20=934px,见 hook 首参),不再死锁 800——大屏留出
+ // 左右呼吸空间、窄屏自适应收窄,且发送后同一个 ChatInput 无宽度跳变。
+ // inputWidth 由 useLayoutEffect 同步量出
// (paint 前已就绪);极端未量到(0)时回落旧默认 800,不放大到全宽。
style={{ maxWidth: inputWidth || 800 }}
>
diff --git a/apps/desktop/src/renderer/hooks/useProportionalWidth.ts b/apps/desktop/src/renderer/hooks/useProportionalWidth.ts
index 83fa4f21f7..fa86e48bcb 100644
--- a/apps/desktop/src/renderer/hooks/useProportionalWidth.ts
+++ b/apps/desktop/src/renderer/hooks/useProportionalWidth.ts
@@ -4,9 +4,13 @@ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
* 主区域内容宽度 hook
*
* 同时返回两个宽度:
- * messageWidth = min(1200, containerWidth - sidePadding*2) // 普通模式 50px/侧
+ * messageWidth = min(maxWidth, containerWidth - sidePadding*2) // 普通模式 50px/侧
* inputWidth = messageWidth + INPUT_OUTSET (输入框每侧少 10px)
*
+ * maxWidth 为内容封顶宽(首参):容器再宽,内容列也不超过它,超出部分靠 mx-auto
+ * 居中留白。不传时回落到 MAX_MESSAGE_WIDTH(1200) 的历史默认。新建对话页与进行中
+ * 对话页传同一个值(914),保证发送首条消息时输入框宽度不跳变,同时左右留出呼吸空间。
+ *
* - 消息流侧 (50px):MessageStream 是 overflow-y-auto 的原生滚动容器,占满
* 全宽 containerWidth,内部 contentRef `mx-auto` + `maxWidth=messageWidth`
* 自然得到左右各 50px 的边距 ((containerWidth - messageWidth) / 2 = 50)。
@@ -30,6 +34,7 @@ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
* messageWidth 先扩出去顶过 parent"的中间帧。doc rail 走显式 `compact: true`
* 仍恒 compact,行为不变。
*/
+// 内容封顶宽的历史默认值:调用方不传首参时回落到它(旧行为)。
const MAX_MESSAGE_WIDTH = 1200;
const INPUT_OUTSET = 20; // 输入框比消息流每侧宽 10px(共 20px)
const DEFAULT_MESSAGE_PAD = 50;
@@ -57,7 +62,7 @@ export interface UseProportionalWidthOptions {
}
export function useProportionalWidth(
- _maxWidth?: number,
+ maxWidth?: number,
opts: UseProportionalWidthOptions = {},
) {
const containerRef = useRef<HTMLDivElement>(null);
@@ -83,7 +88,9 @@ export function useProportionalWidth(
const messagePad = useCompact ? COMPACT_MESSAGE_PAD : DEFAULT_MESSAGE_PAD;
const nextInputPad = Math.max(0, messagePad - INPUT_OUTSET / 2);
const messageAvailable = Math.max(0, containerWidth - messagePad * 2);
- const nextMessage = Math.min(MAX_MESSAGE_WIDTH, messageAvailable);
+ // 首参 maxWidth 为内容封顶宽;非法/未传时回落到历史默认 1200。
+ const cap = maxWidth && maxWidth > 0 ? maxWidth : MAX_MESSAGE_WIDTH;
+ const nextMessage = Math.min(cap, messageAvailable);
let nextInput = nextMessage + INPUT_OUTSET;
if (opts.minWidth && opts.minWidth > nextInput) {
// 地板夹到实测容器宽以内:窄窗仍是"填满容器",不会溢出/裁切。
@@ -94,7 +101,7 @@ export function useProportionalWidth(
setInputPad(nextInputPad);
setIsCompact(useCompact);
},
- [opts.compact, opts.minWidth],
+ [maxWidth, opts.compact, opts.minWidth],
);
// useLayoutEffect + 同步量一次:消除 mount 第一帧 width=0 的视觉跳变。