Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 纯附件私聊消息保留操作入口,选择文字保留代码原文
zqchrisc9dfa9c75eec
diff --git a/apps/mobile/src/__tests__/messageMediaThumbnailWiring.test.ts b/apps/mobile/src/__tests__/messageMediaThumbnailWiring.test.tsindex 8a38ceea32..6b5530c2a8 100644--- a/apps/mobile/src/__tests__/messageMediaThumbnailWiring.test.ts+++ b/apps/mobile/src/__tests__/messageMediaThumbnailWiring.test.ts@@ -77,7 +77,7 @@ describe('mobile message media thumbnail wiring', () => {expect(rendererSource).toContain('{attachmentStripNode}');// 普通消息仍按原判据省略空气泡;外层现在先分流独立错误卡片。expect(rendererSource).toContain(- 'hasBubbleContent || (!attachmentStripNode && messageQuotes.length === 0) ? (',+ '&& (hasBubbleContent || (!attachmentStripNode && messageQuotes.length === 0));',);const attachmentStrip = rendererSource.slice(rendererSource.indexOf('function AttachmentStrip'),@@ -120,7 +120,7 @@ describe('mobile message media thumbnail wiring', () => {expect(pendingBranch).toContain('<FileChip');expect(pendingBranch).toContain('<MarkdownBody');expect(pendingBranch).not.toContain('onOpenPayload=');- expect(pending.indexOf('<AttachmentThumbStrip')).toBeLessThan(pending.indexOf('{hasBody ?'));+ expect(pending.indexOf('<AttachmentThumbStrip')).toBeLessThan(pending.indexOf('{hasBody || (item.replyQuote && renderReplyQuote) ?'));expect(pending).toContain('item.fileNames.map(renderFile)');expect(pending).not.toContain('height: 72');expect(pending).not.toContain('contentFit="cover"');diff --git a/apps/mobile/src/__tests__/selectableMessageText.test.ts b/apps/mobile/src/__tests__/selectableMessageText.test.tsnew file mode 100644index 0000000000..9a1b3fc93a--- /dev/null+++ b/apps/mobile/src/__tests__/selectableMessageText.test.ts@@ -0,0 +1,14 @@+// Unit tier: the 「选择文字」 sheet copies what this returns, so code must come out exactly as shown.+import { describe, expect, it } from 'vitest';+import { selectableMessageText } from '@/session/selectableMessageText';++describe('selectableMessageText', () => {+ it('drops Markdown marks from prose', () => {+ expect(selectableMessageText('## Title\n- **bold** and [link](https://x.y)')).toBe('Title\n• bold and link');+ });++ it('keeps fenced and inline code verbatim', () => {+ const markdown = 'Run `print("**value**")` first.\n```python\n# important\nx = "**value**"\n```';+ expect(selectableMessageText(markdown)).toBe('Run print("**value**") first.\n# important\nx = "**value**"');+ });+});diff --git a/apps/mobile/src/session/CompanionSelectTextSheet.tsx b/apps/mobile/src/session/CompanionSelectTextSheet.tsxindex ef968618a1..3bb35306db 100644--- a/apps/mobile/src/session/CompanionSelectTextSheet.tsx+++ b/apps/mobile/src/session/CompanionSelectTextSheet.tsx@@ -10,17 +10,7 @@ import { Text } from '@/components/AppText';import { useThemedStyles, type ThemeColors } from '@/theme';import { lineHeight, spacing, typeScale } from '@/theme/tokens';import { CompanionSheet } from './CompanionSheet';--/** What the reader sees, without Markdown syntax: emphasis marks, link targets and heading hashes go. */-export function selectableMessageText(markdown: string): string {- return markdown- .replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')- .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')- .replace(/^#{1,6}\s+/gm, '')- .replace(/^(\s*)[-*+]\s+/gm, '$1• ')- .replace(/(\*\*|__)(.+?)\1/g, '$2')- .replace(/`([^`\n]+)`/g, '$1');-}+import { selectableMessageText } from './selectableMessageText';export function CompanionSelectTextSheet({ text, onClose }: { text: string; onClose: () => void }) {const { t } = useTranslation();diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsxindex 30a73de5f6..111288f637 100644--- a/apps/mobile/src/session/MessageRenderer.tsx+++ b/apps/mobile/src/session/MessageRenderer.tsx@@ -3094,7 +3094,8 @@ const RenderItemView = memo(function RenderItemView({renderReplyQuote={actions.companionQuoteActions ? (quote) => (<View style={styles.companionQuote}><BotGroupQuote display={companionReplyQuoteDisplay(quote,- actions.companionQuoteActions!.getMessage(quote.clientId), actions.companionQuoteActions!.names)} />+ actions.companionQuoteActions!.getMessage(quote.clientId), actions.companionQuoteActions!.names)}+ onPress={() => actions.companionQuoteActions!.onLocate(quote.clientId)} /></View>) : undefined}onOpenImage={actions.onOpenPayload}@@ -3882,7 +3883,13 @@ function MessageBubble({&& Boolean(item.message.pluginInvocations?.length);const hasBubbleContent = !!(item.message.systemCardType || displayBubbleBody || item.message.secondaryBody || hasPluginInvocations+ // A quote or reply target alone still needs the bubble, e.g. an attachment-only reply.+ || (companionQuote && (replyQuote || replyTarget)));+ // The long-press menu lives on the bubble; without one (attachment-only, error) the action row stays.+ const bubbleShown = item.message.role !== 'error'+ && (hasBubbleContent || (!attachmentStripNode && messageQuotes.length === 0));+ const companionMenuMounted = companionMenuEnabled && bubbleShown;// 气泡是纯 View,不承接任何手势:文本选择走正文原生 Text selectable(长按文字就地选择复制),// 气泡上不能挂 Pressable——它会参与触摸协商,干扰正文里表格/代码块横向 ScrollView 的拖动。const bubble = (@@ -4130,7 +4137,7 @@ function MessageBubble({<ErrorNotice message={displayBubbleBody}>{item.message.rawError ? <AgentErrorDetails key={item.message.key} message={item.message.rawError} /> : null}</ErrorNotice>- ) : hasBubbleContent || (!attachmentStripNode && messageQuotes.length === 0) ? (+ ) : bubbleShown ? (companionMenuEnabled ? (Platform.OS === 'ios' ? (<GestureDetector gesture={companionMenuGesture}><View style={isUser ? styles.companionMenuUser : styles.companionMenuAgent} testID="companion.messageMenu">@@ -4168,7 +4175,7 @@ function MessageBubble({</Text></View>) : null}- {companionMenuEnabled ? null : hasActions && actions.companion ? <CompanionMessageActions user={isUser} copied={copyState === 'copied'} copying={copyState === 'copying'} disabled={disabled}+ {companionMenuMounted ? null : hasActions && actions.companion ? <CompanionMessageActions user={isUser} copied={copyState === 'copied'} copying={copyState === 'copying'} disabled={disabled}onCopy={canCopy ? copyMessage : undefined}actions={[...(canCopy ? [{ id: 'copy', title: copyActionLabel(copyState), image: 'doc.on.doc', disabled: copyState === 'copying' }] : []),diff --git a/apps/mobile/src/session/PendingSendBubble.tsx b/apps/mobile/src/session/PendingSendBubble.tsxindex 3bce96f113..2ffef77363 100644--- a/apps/mobile/src/session/PendingSendBubble.tsx+++ b/apps/mobile/src/session/PendingSendBubble.tsx@@ -521,7 +521,7 @@ export function PendingSendBubble({) : null}</View>) : null}- {hasBody ? (+ {hasBody || (item.replyQuote && renderReplyQuote) ? (<MessageBodyTapBoundary value={cancelBubbleTouch}><Viewkey={`body:${item.clientId}`}diff --git a/apps/mobile/src/session/selectableMessageText.ts b/apps/mobile/src/session/selectableMessageText.tsnew file mode 100644index 0000000000..45ae924e9a--- /dev/null+++ b/apps/mobile/src/session/selectableMessageText.ts@@ -0,0 +1,32 @@+/**+ * 「选择文字」面板里的正文(docs/product-rules/cindy-bots-runtime.md「私聊引用回复」手机端):+ * 去掉 Markdown 记号,只留读者看到的文字;代码块与行内代码保持原文,复制出来的代码与气泡里一致。+ */+const FENCE_LINE = /^\s*(```|~~~)/;++function plainProse(text: string): string {+ return text+ .replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')+ .replace(/(\*\*|__)(.+?)\1/g, '$2');+}++function plainLine(line: string): string {+ const prose = line.replace(/^#{1,6}\s+/, '').replace(/^(\s*)[-*+]\s+/, '$1• ');+ // Odd parts are inline code: keep their content as is, only drop the backticks.+ return prose.split(/(`[^`\n]+`)/).map((part, index) => (index % 2 ? part.slice(1, -1) : plainProse(part))).join('');+}++export function selectableMessageText(markdown: string): string {+ let fence: string | null = null;+ const lines: string[] = [];+ for (const line of markdown.split('\n')) {+ const marker = FENCE_LINE.exec(line)?.[1];+ if (marker && (!fence || marker === fence)) {+ fence = fence ? null : marker;+ continue;+ }+ lines.push(fence ? line : plainLine(line));+ }+ return lines.join('\n');+}diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 19542bd1ee..d56793fe92 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -94,8 +94,8 @@ Chris:「私聊话题和群聊话题,要真的能把独立事件隔离到独- **手机端(2026-10-22)**:长按私聊气泡打开消息菜单(iOS 为系统操作表,标题是准确时间;Android 为原生长按菜单),依次是回复、复制、选择文字、分享,以及原有的消息链接、回到这里与删除。长按只用 RNGH LongPress(450ms,手指一动即失败),表格和代码块照旧横向滚动;因此私聊气泡正文不再就地选择,改由「选择文字」面板做部分选择(iOS 用- UITextView,去掉 Markdown 记号)。回复在输入框上方放同一种待发引用(卡片底色,× 取消),随普通发送、离线发件箱- 与排队编辑一起保留在信封 `replyQuote` 里;待发、已发气泡顶部都显示引用块,点击定位原消息。信封解析与摘要和+ UITextView,去掉 Markdown 记号,代码块与行内代码保持原文)。回复在输入框上方放同一种待发引用(卡片底色,× 取消),随普通发送、离线发件箱+ 与排队编辑一起保留在信封 `replyQuote` 里;待发、已发气泡顶部都显示引用块(只发附件时也显示),点击定位原消息;没有正文气泡的消息(纯附件、错误)保留原操作行。信封解析与摘要和Desktop 共用 `@cindy/maker-shared/chat-reply-quote`。实现见 Mobile `companionReplyQuote.ts`、`CompanionSelectTextSheet.tsx` 与 `MessageRenderer.tsx`。