Reuse chat table cell measurements across rebuilds
A markdown table measures each cell's paragraph at infinite width before laying it out. Cells rebuilt when a row scrolls back in or a chat is opened again now reuse those widths from a bounded cache keyed by the cell markdown and its paragraph style, cleared when fonts change. Layout is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_table_cell_measure.dart';
|
||||
|
||||
import 'chat_markdown_test_support.dart';
|
||||
|
||||
@@ -51,4 +53,46 @@ void main() {
|
||||
await pumpTable(tester, '| a | b |\n| --- | --- |\n| 1 | 2 |');
|
||||
expect(tableRect(tester).width, lessThan(screenRight / 2));
|
||||
});
|
||||
|
||||
group('cell measurements', () {
|
||||
const table =
|
||||
'| Item | Description |\n| --- | --- |\n'
|
||||
'| one | some longer words that need to wrap inside the cell |\n'
|
||||
'| two | `code` and **bold** text |';
|
||||
|
||||
setUp(ChatTableCellWidths.clear);
|
||||
|
||||
Future<Rect> pumpFresh(WidgetTester tester) async {
|
||||
// An empty frame first, so the table gets new render objects.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await pumpTable(tester, table);
|
||||
return tableRect(tester);
|
||||
}
|
||||
|
||||
testWidgets('a rebuilt table reuses them with the same layout', (
|
||||
tester,
|
||||
) async {
|
||||
final first = await pumpFresh(tester);
|
||||
final measured = ChatTableCellWidths.measured;
|
||||
// Six cells, each measured for its widest line and longest word.
|
||||
expect(measured, greaterThanOrEqualTo(12));
|
||||
final again = await pumpFresh(tester);
|
||||
expect(ChatTableCellWidths.measured, measured);
|
||||
expect(again, first);
|
||||
});
|
||||
|
||||
testWidgets('a font change measures again', (tester) async {
|
||||
await pumpFresh(tester);
|
||||
final measured = ChatTableCellWidths.measured;
|
||||
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||
SystemChannels.system.name,
|
||||
SystemChannels.system.codec.encodeMessage(<String, Object?>{
|
||||
'type': 'fontsChange',
|
||||
}),
|
||||
(_) {},
|
||||
);
|
||||
await pumpFresh(tester);
|
||||
expect(ChatTableCellWidths.measured, greaterThan(measured));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user