Wrap chat markdown tables to the transcript width

Tables no longer scroll sideways: columns size to content and shrink to
fit, wrapping cell text; an unbreakable token breaks inside its cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 10:15:12 +00:00
parent b264043eee
commit 93e9042a8b
6 changed files with 154 additions and 22 deletions
@@ -149,7 +149,7 @@ void main() {
},
);
testWidgets('code and table labels identify the scrollable region', (
testWidgets('a code block scrolls sideways while a table wraps', (
tester,
) async {
await tester.pumpWidget(
@@ -167,9 +167,14 @@ void main() {
);
expect(
find.bySemanticsLabel('Horizontally scrollable table'),
findsOneWidget,
findsNothing,
);
expect(find.text('Scroll horizontally'), findsOneWidget);
final viewport = tester.getRect(find.byType(ChatMarkdownView));
expect(
tester.getRect(find.byType(Table)).right,
lessThanOrEqualTo(viewport.right),
);
expect(find.text('Scroll horizontally'), findsNWidgets(2));
expect(tester.takeException(), isNull);
});
}
@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import 'chat_markdown_test_support.dart';
void main() {
Future<void> pumpTable(WidgetTester tester, String text) async {
await phoneViewport(tester);
await tester.pumpWidget(markdownHost(ChatMarkdownView(text: text)));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
}
Rect tableRect(WidgetTester tester) => tester.getRect(find.byType(Table));
// The phone viewport is 390 logical pixels wide.
const screenRight = 390.0;
testWidgets('a wide table wraps its cells inside the transcript', (
tester,
) async {
await pumpTable(
tester,
'| Item | Description | Status |\n| --- | --- | --- |\n'
'| one | ${List.filled(30, 'word').join(' ')} | done |',
);
expect(
find.descendant(
of: find.byType(ChatMarkdownView),
matching: find.byType(Scrollable),
),
findsNothing,
);
expect(tableRect(tester).right, lessThanOrEqualTo(screenRight));
final description = tester.getSize(find.textContaining('word word'));
final status = tester.getSize(find.text('done'));
// The long cell wrapped onto several lines; the short one did not.
expect(description.height, greaterThan(status.height * 2));
});
testWidgets('an unbreakable token breaks inside its cell', (tester) async {
await pumpTable(
tester,
'| Path | Note |\n| --- | --- |\n'
'| ${'a' * 200} | ${'b' * 200} |',
);
expect(tableRect(tester).right, lessThanOrEqualTo(screenRight));
});
testWidgets('a narrow table keeps its content width', (tester) async {
await pumpTable(tester, '| a | b |\n| --- | --- |\n| 1 | 2 |');
expect(tableRect(tester).width, lessThan(screenRight / 2));
});
}