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): 拖分隔条按实测宽算可让空间,弹性 chat 不再被账面卡半路

Lizi05faa17d878a
diff --git a/apps/desktop/src/renderer/layout/LayoutRoot.tsx b/apps/desktop/src/renderer/layout/LayoutRoot.tsx
index b8ff8b37bc..be53a559ae 100644
--- a/apps/desktop/src/renderer/layout/LayoutRoot.tsx
+++ b/apps/desktop/src/renderer/layout/LayoutRoot.tsx
@@ -308,11 +308,15 @@ function RootDivider({
};
/**
- * 一侧能让出的份额余量 = min(账面余量, 实测余量, 账本地板余量),三条都不能越:
- * - **账面余量** share × avail − 面板最小宽:在场份额口径下账面即画面,拖动
- * 从第一像素就跟手;
- * - **实测余量** 实测元素宽 − 面板最小宽:面板被 CSS 收成 0 宽(折叠态)或被
- * min-width 顶住时,账面会高估它能让出的地方,实测才是真相;
+ * 一侧能让出的份额余量 = min(可让像素余量, 账本地板余量),两条都不能越:
+ * - **可让像素余量** 该面板当前宽 − 面板最小宽。**量得到实测宽就以实测为准** ——
+ * 账面(share × avail)两头都会错:面板被 CSS 收成 0 宽(折叠态)或被 min-width
+ * 顶住时账面**高估**;弹性 chat 吸收了折叠邻居(如收起的右侧栏)让出的地方时,
+ * 那份空间记在邻居账上、画面却归了 chat,账面又**低估** chat 能让的地方。
+ * (2026-07-31 Lizi 实测:右侧栏折叠成 0 宽时拖别的面板变大,chat 到一半就卡 ——
+ * 旧实现取 min(账面, 实测) 用了低估的账面,把 chat 真实可让空间压没了。)
+ * 量不到实测(jsdom / 元素未挂载)才回退,并对回退值保留 min(账面, 回退) 下限
+ * ——历史行为,避免无实测时凭账面高估空拖一段。
* - **地板余量** (树份额 − 0.05) / scale:transferSplitFraction 对让某一侧跌破
* 0.05 的转移整单拒绝 —— 实时拖动必须同受此限,否则松手写树失败、整段位移
* 作废,界面弹回原宽(2026-07-29 Lizi 实测右栏拖到最大就回弹的根因:树里
@@ -322,8 +326,10 @@ function RootDivider({
if (!(avail > 0)) return 0; // 可用宽异常:不给余量,免得 0/0 产出 NaN 份额
const minPx = paneMinPx(entry.node);
const ledgerPx = entry.share * avail;
- const realPx = measuredPanePx(entry.node) ?? fallbackPx ?? ledgerPx;
- const pxRoom = Math.min(ledgerPx, realPx) - minPx;
+ const measured = measuredPanePx(entry.node);
+ // 实测可信直接用;量不到才回退账面/兜底,并保留 min 下限(与历史一致,不扰动)。
+ const basisPx = measured ?? Math.min(ledgerPx, fallbackPx ?? ledgerPx);
+ const pxRoom = basisPx - minPx;
const floorRoom =
shareScale > 0 ? (entry.fraction - MIN_SPLIT_CHILD_FRACTION) / shareScale : 0;
return Math.max(0, Math.min(pxRoom / avail, floorRoom));
diff --git a/apps/desktop/src/renderer/layout/__tests__/rootDividerDrag.test.tsx b/apps/desktop/src/renderer/layout/__tests__/rootDividerDrag.test.tsx
index e497e017be..91e0403b08 100644
--- a/apps/desktop/src/renderer/layout/__tests__/rootDividerDrag.test.tsx
+++ b/apps/desktop/src/renderer/layout/__tests__/rootDividerDrag.test.tsx
@@ -82,6 +82,17 @@ function renderLayoutRoot() {
);
}
+/**
+ * 覆盖 jsdom 恒为 0 的矩形:给某 panelKind 的元素钉死一个实测宽,让起拖时
+ * measuredPanePx 拿到真机口径的宽度(而非回落账面)。
+ */
+function mockPaneWidth(kind: string, width: number): void {
+ const el = document.querySelector(`[data-panel-drag-root="${kind}"]`) as HTMLElement | null;
+ expect(el).not.toBeNull();
+ el!.getBoundingClientRect = () =>
+ ({ width, height: 0, top: 0, left: 0, right: width, bottom: 0, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect;
+}
+
/** 把缝一路拖向左(右侧面板变宽)到抓不动为止,松手。 */
function dragDividerLeft(container: HTMLElement, byPx: number): void {
const grab = container.querySelector('[data-testid="layout-divider"] > div');
@@ -163,4 +174,26 @@ describe('RootDivider 拖宽 · 在场份额口径', () => {
expect(setCalls).toHaveLength(1);
expect(committedShares()['right-tabs'].px).toBeCloseTo(120, 0);
});
+
+ // 2026-07-31 Lizi 实测:右侧栏折叠成 0 宽时拖 chat 变小(反向即拖别的面板变大),
+ // chat 到一半就卡。根因:折叠邻居让出的地方被弹性 chat 吸收,chat 实测宽远大于账面
+ // (share × avail),旧实现取 min(账面, 实测) 用了低估的账面,把 chat 真实可让空间压没了。
+ it('实测宽 > 账面宽(折叠邻居把份额让给了弹性 chat):按实测算可让空间,不被账面卡住', () => {
+ currentLayout = createDefaultLayout(); // chat / right 各半
+ const split = currentLayout.content as SplitNode;
+ split.children[0].fraction = 0.6; // chat:账面 0.6 → 账面宽 996px
+ split.children[1].fraction = 0.4; // right-tabs
+ const { container } = renderLayoutRoot();
+ // 真机:右栏折叠成 ~0,那 0.4 的地方被 chat 吸收 → chat 实测 1200px(账面才 996)。
+ const realChatPx = 1200;
+ mockPaneWidth('chat-main', realChatPx);
+ mockPaneWidth('right-tabs', 0);
+ dragDividerLeft(container, 1000); // 一路压缩 chat 到抓不动
+
+ expect(setCalls).toHaveLength(1); // 写树成功,没回弹
+ // 修复后按实测算:chat 能让 realPx − 400 = 800px(份额 800/1660),chat 落到约 0.118。
+ // 旧实现被账面 996 卡住:只让 min(996,1200)−400 = 596px(份额 0.359),chat 停在 0.241。
+ const givenShare = (realChatPx - CHAT_MIN) / AVAIL;
+ expect(committedShares()['chat-main'].fraction).toBeCloseTo(0.6 - givenShare, 3);
+ });
});