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): 修复分享选择框被裁切 (#2424)

Dash46c6c32e85ee
diff --git a/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts b/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts
new file mode 100644
index 0000000000..9b21415897
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts
@@ -0,0 +1,44 @@
+/**
+ * 回归:分享选择模式在长 assistant 正文末尾动态挂载选择框时,消息 item 不能继续
+ * 使用 content-visibility 的 intrinsic 占位。否则绝对定位的 20px 选择框会按缓存
+ * 盒裁切成近乎不可见的高度。jsdom 不计算这组布局,所以这里锁住 DOM/CSS 契约。
+ */
+
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { describe, expect, it } from 'vitest';
+
+const readRendererSource = (relativePath: string): string =>
+ readFileSync(resolve(__dirname, '..', relativePath), 'utf8').replace(/\r\n/g, '\n');
+
+const messageStreamSource = readRendererSource('components/chat/MessageStream.tsx');
+const globalsSource = readRendererSource('styles/globals.css');
+
+function cssRuleBody(selector: string): string {
+ const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ return globalsSource.match(new RegExp(`${escaped}\\s*\\{([\\s\\S]*?)\\}`))?.[1] ?? '';
+}
+
+describe('分享选择模式的消息布局隔离', () => {
+ it('只在分享选择激活时给消息流容器挂状态属性', () => {
+ expect(messageStreamSource).toContain(
+ "data-share-selection-active={shareSelectionActive ? '' : undefined}",
+ );
+ });
+
+ it('常态消息仍保留 content-visibility 性能优化', () => {
+ const rule = cssRuleBody('.msg-stream-items > *');
+
+ expect(rule).toContain('content-visibility: auto;');
+ expect(rule).toContain('contain-intrinsic-size: auto 240px;');
+ });
+
+ it('分享模式下仅让可分享消息使用真实布局盒', () => {
+ const rule = cssRuleBody(
+ '.msg-stream-items[data-share-selection-active] > [data-share-message-id]',
+ );
+
+ expect(rule).toContain('content-visibility: visible;');
+ expect(rule).toContain('contain-intrinsic-size: none;');
+ });
+});
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index 7b482887b2..fc0fa76179 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -4150,6 +4150,7 @@ export function MessageStream({
态丢失 / 滚动锚点漂走。 */}
<div
ref={itemsRef}
+ data-share-selection-active={shareSelectionActive ? '' : undefined}
className={cn(
// msg-stream-items:直接子元素(每条 render item 的根节点)带
// content-visibility:auto(globals.css)—— 视口外条目跳过布局
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index 635c84df02..f13cffde1e 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -1174,6 +1174,14 @@ body.resizing-pane [data-ghost-webview] {
contain-intrinsic-size: none;
}
+/* 分享选择模式会在消息 wrapper 左侧动态挂载绝对定位的选择框。该元素需要真实
+ 消息盒参与布局与绘制;继续使用视口外 intrinsic 占位会让长消息末尾的选择框
+ 被压缩或裁切。仅让可分享消息退出隔离,常态和工具类条目继续保留渲染跳过。 */
+.msg-stream-items[data-share-selection-active] > [data-share-message-id] {
+ content-visibility: visible;
+ contain-intrinsic-size: none;
+}
+
/* 会话切换 shell-first 帧的品牌加载指示(BrandLoadingMark):
wordmark 低亮常驻 + 亮带经同形 mask 在字标形状内扫过(Codex Desktop
startup loader 同构表现)。两条硬约束: