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(mobile): 按图片替代文字计算群聊表格列宽

zcinta0514d503bc47b3bf
diff --git a/apps/mobile/src/__tests__/BotGroupMarkdownText.test.tsx b/apps/mobile/src/__tests__/BotGroupMarkdownText.test.tsx
index dc6a4ad916..7bbcfb6e50 100644
--- a/apps/mobile/src/__tests__/BotGroupMarkdownText.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupMarkdownText.test.tsx
@@ -106,3 +106,21 @@ it('keeps component literal punctuation and Markdown formatting distinct', async
expect(styleOf('authored bold')).toMatchObject({ fontWeight: '600' });
expect(node.textContent).not.toContain('"op":"create"');
});
+
+// #6716 review: group images render as alt text, not 150px native previews.
+it.each([['x', ''], ['a long image description that wraps inside its column', 'y']])(
+ 'measures image cells like their visible fallback text (%s / %s)', async (alt, otherAlt) => {
+ const renderTable = async (first: string, second: string) => {
+ await act(async () => root.render(createElement(BotGroupMarkdownText, {
+ content: `| ${first} | ${second} |\n| --- | --- |\n| ${second} | ${first} |`, authorKind: 'bot',
+ })));
+ const row = node.querySelector('section')!.firstElementChild!.firstElementChild!;
+ return [...row.children].map(cell => JSON.parse(cell.getAttribute('data-style')!).width);
+ };
+ const imageWidths = await renderTable(`![${alt}](https://example.com/a.png)`, `![${otherAlt}](https://example.com/b.png)`);
+ expect(node.textContent).toBe([alt, otherAlt, otherAlt, alt].map(text => text ? `[${text}]` : '').join(''));
+ const textWidths = await renderTable(alt ? `[${alt}]` : '', otherAlt ? `[${otherAlt}]` : '');
+ expect(imageWidths).toEqual(textWidths);
+ if (!otherAlt) expect(imageWidths.reduce((a, b) => a + b, 0)).toBe(280);
+ },
+);
diff --git a/apps/mobile/src/debug/visualMock.ts b/apps/mobile/src/debug/visualMock.ts
index 5e3ed18570..dc1c93e179 100644
--- a/apps/mobile/src/debug/visualMock.ts
+++ b/apps/mobile/src/debug/visualMock.ts
@@ -222,6 +222,8 @@ async function visualMockInvoke<T = unknown>(
const content = [
'窄屏表格:短表铺满正文,宽表横向滑动。',
'', '| A | B |', '| --- | --- |', '| 1 | 2 |', '| 3 | [链接](https://example.com) |',
+ '', '| ![x](https://example.com/a.png) | ![](https://example.com/b.png) |', '| --- | --- |',
+ '| ![](https://example.com/b.png) | ![y](https://example.com/a.png) |',
'', '| 项目 | 说明 | 状态 | 最后一列 |', '| --- | --- | --- | --- |',
'| A | **长说明在单元格内换行,行高应随内容增加,下一行仍按相同列宽对齐。** | 完成 | 末列可见 |',
'| B | | 进行中 | 末列第二行 |',
diff --git a/apps/mobile/src/session/BotGroupMessageText.tsx b/apps/mobile/src/session/BotGroupMessageText.tsx
index 7b6ff44e7a..679e910943 100644
--- a/apps/mobile/src/session/BotGroupMessageText.tsx
+++ b/apps/mobile/src/session/BotGroupMessageText.tsx
@@ -50,8 +50,14 @@ function BotGroupMarkdownTable({ block, styles }: {
const onLayout = useCallback((event: LayoutChangeEvent) => {
setAvailableWidth(event.nativeEvent.layout.width);
}, []);
+ // This read-only renderer shows image alt text, so measure that same text, not a preview.
+ const measureCells = (cells: readonly MobileMarkdownInline[][]) => cells.map(cell => cell.map(
+ (inline): MobileMarkdownInline => inline.type === 'image'
+ ? { type: 'text', text: inline.alt ? `[${inline.alt}]` : '' }
+ : inline,
+ ));
const widths = buildMobileMarkdownTableColumnWidths({
- header: block.header, rows: block.rows, availableWidth,
+ header: measureCells(block.header), rows: block.rows.map(row => ({ ...row, cells: measureCells(row.cells) })), availableWidth,
minWidth: buildMessageContentLayout({ screenWidth }).markdownTableCellMinWidth,
});
const renderRow = (cells: readonly MobileMarkdownInline[][], key: string, header = false) => (