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): 修复伙伴分享聊天选择框被裁切 (#4985)

Dash26bd6d86f657
diff --git a/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx b/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
index 6354b45195..5f3bb168cc 100644
--- a/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/composerChipPresentation.test.tsx
@@ -93,7 +93,7 @@ describe('composer atomic chip presentation', () => {
// 规则体用 [^}] 界定,不假设 `}` 前面正好是换行:CSS 声明里不会出现 `}`,
// 所以缩进或换行风格调整不会再让这条断言失配(同下面那条间距用例)。
const alignmentRule = globalsSource.match(
- /\.ProseMirror :is\(\[data-mention-chip\], \[data-pasted-text-chip\], \[data-composer-quote\]\)\s*\{([^}]*)\}/,
+ /\.ProseMirror\s+:is\(\[data-mention-chip\], \[data-pasted-text-chip\], \[data-composer-quote\]\)\s*\{([^}]*)\}/,
)?.[1];
expect(alignmentRule).toContain('position: relative');
@@ -106,7 +106,7 @@ describe('composer atomic chip presentation', () => {
// (如 #599 的 .quick-start-pill)。写死完整列表会让那类改动把断言变成
// gapRule === undefined,报出与本意无关的 "undefined and string" 断言错误。
const gapRuleMatch = [
- ...globalsSource.matchAll(/\.ProseMirror :is\(([^)]*)\)\s*\{([^}]*)\}/g),
+ ...globalsSource.matchAll(/\.ProseMirror\s+:is\(([^)]*)\)\s*\{([^}]*)\}/g),
].find(([, , body]) => body.includes('margin-inline'));
const [, gapSelectors, gapRule] = gapRuleMatch ?? [];
diff --git a/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts b/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts
index 9b21415897..aa010f72bd 100644
--- a/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts
+++ b/apps/desktop/src/renderer/__tests__/shareSelectionContainment.test.ts
@@ -6,6 +6,7 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
+import { parse } from 'postcss';
import { describe, expect, it } from 'vitest';
const readRendererSource = (relativePath: string): string =>
@@ -13,10 +14,14 @@ const readRendererSource = (relativePath: string): string =>
const messageStreamSource = readRendererSource('components/chat/MessageStream.tsx');
const globalsSource = readRendererSource('styles/globals.css');
+const globalsCss = parse(globalsSource);
function cssRuleBody(selector: string): string {
- const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
- return globalsSource.match(new RegExp(`${escaped}\\s*\\{([\\s\\S]*?)\\}`))?.[1] ?? '';
+ let body = '';
+ globalsCss.walkRules((rule) => {
+ if (rule.selectors.includes(selector)) body += rule.toString();
+ });
+ return body;
}
describe('分享选择模式的消息布局隔离', () => {
@@ -33,10 +38,11 @@ describe('分享选择模式的消息布局隔离', () => {
expect(rule).toContain('contain-intrinsic-size: auto 240px;');
});
- it('分享模式下仅让可分享消息使用真实布局盒', () => {
- const rule = cssRuleBody(
- '.msg-stream-items[data-share-selection-active] > [data-share-message-id]',
- );
+ it.each([
+ '.msg-stream-items[data-share-selection-active] > [data-share-message-id]',
+ '.msg-stream-items[data-share-selection-active] > :has([data-share-message-id])',
+ ])('分享模式下可分享消息使用真实布局盒:%s', (selector) => {
+ const rule = cssRuleBody(selector);
expect(rule).toContain('content-visibility: visible;');
expect(rule).toContain('contain-intrinsic-size: none;');
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index f79dfbff21..4a3052e020 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -652,14 +652,15 @@ html:lang(ko) {
/* Keep the caret and surrounding prose a consistent, readable distance from
every composer pill. This is external spacing, independent of chip padding. */
-.ProseMirror :is(
- [data-mention-chip],
- [data-pasted-text-chip],
- [data-composer-quote],
- .ghost-cmd-pill,
- .slash-cmd-pill,
- .quick-start-pill
-) {
+.ProseMirror
+ :is(
+ [data-mention-chip],
+ [data-pasted-text-chip],
+ [data-composer-quote],
+ .ghost-cmd-pill,
+ .slash-cmd-pill,
+ .quick-start-pill
+ ) {
margin-inline: 4px;
}
@@ -1132,8 +1133,10 @@ body.resizing-pane [data-ghost-webview] {
/* 分享选择模式会在消息 wrapper 左侧动态挂载绝对定位的选择框。该元素需要真实
消息盒参与布局与绘制;继续使用视口外 intrinsic 占位会让长消息末尾的选择框
- 被压缩或裁切。仅让可分享消息退出隔离,常态和工具类条目继续保留渲染跳过。 */
-.msg-stream-items[data-share-selection-active] > [data-share-message-id] {
+ 被压缩或裁切。伙伴消息的分享 wrapper 位于含时间分组的条目内部,也必须让
+ 外层条目退出隔离;常态和工具类条目继续保留渲染跳过。 */
+.msg-stream-items[data-share-selection-active] > [data-share-message-id],
+.msg-stream-items[data-share-selection-active] > :has([data-share-message-id]) {
content-visibility: visible;
contain-intrinsic-size: none;
}
@@ -1158,12 +1161,7 @@ body.resizing-pane [data-ghost-webview] {
position: absolute;
inset: 0;
width: 45%;
- background: linear-gradient(
- 100deg,
- transparent 10%,
- var(--text-primary) 50%,
- transparent 90%
- );
+ background: linear-gradient(100deg, transparent 10%, var(--text-primary) 50%, transparent 90%);
transform: translateX(-120%);
animation: brand-loading-sheen 1.6s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}