# Conflicts:
#	app/lib/features/chat/ui/transcript/chat_markdown_view.dart
This commit is contained in:
2026-11-21 17:11:45 +00:00
23 changed files with 1267 additions and 43 deletions
@@ -12,14 +12,18 @@ import 'chat_markdown.dart';
import 'chat_markdown_cache.dart';
import 'chat_markdown_speech.dart';
import 'chat_message_bubble.dart';
<<<<<<< HEAD
import '../../speech/speech.dart';
=======
import 'chat_table_column_width.dart';
>>>>>>> 059eb1bb0d6978e2caf9feb3545d40ee8242022e
/// Renders one assistant text part with native text widgets and the host's own
/// theme roles. Links (`http`, `https`, `mailto` and `www.` hosts only) open
/// through [onOpenLink] when given, else the [ChatLinkScope] launcher, which by
/// default opens them outside the app. No font family, size, colour or component
/// dimension is overridden; code keeps its exact whitespace and scrolls
/// sideways instead of widening the transcript.
/// sideways instead of widening the transcript, while table cells wrap.
class ChatMarkdownView extends StatefulWidget {
const ChatMarkdownView({
super.key,
@@ -227,24 +231,22 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
),
);
case MarkdownTable(header: final header, rows: final rows):
return ChatTranscriptHorizontalScrollView(
label: 'table',
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
border: TableBorder.all(color: _dividerColor(context)),
children: [
// Cells wrap to the transcript width; the table never scrolls sideways.
return Table(
defaultColumnWidth: ChatTableColumnWidth(header.length),
border: TableBorder.all(color: _dividerColor(context)),
children: [
TableRow(
decoration: BoxDecoration(color: _headerFill(context)),
children: [
for (final cell in header) _cell(context, cell, header: true),
],
),
for (final row in rows)
TableRow(
decoration: BoxDecoration(color: _headerFill(context)),
children: [
for (final cell in header) _cell(context, cell, header: true),
],
children: [for (final cell in row) _cell(context, cell)],
),
for (final row in rows)
TableRow(
children: [for (final cell in row) _cell(context, cell)],
),
],
),
],
);
case MarkdownCode(language: final language, code: final code):
_skipCodeBlock(code);
@@ -0,0 +1,33 @@
import 'dart:math' as math;
import 'package:flutter/widgets.dart';
/// Sizes a markdown table column to its content but lets it wrap to fit the
/// transcript instead of scrolling sideways.
///
/// A column asks for its widest line ([IntrinsicColumnWidth]). When the table
/// is wider than its container, [Table] shrinks columns towards their minimum,
/// which is normally the longest single word. That floor is capped at an equal
/// share of the container, so a long identifier or URL breaks inside its cell
/// rather than pushing the table past the edge.
class ChatTableColumnWidth extends TableColumnWidth {
const ChatTableColumnWidth(this.columnCount);
final int columnCount;
static const _content = IntrinsicColumnWidth();
@override
double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) =>
_content.maxIntrinsicWidth(cells, containerWidth);
@override
double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) {
final words = _content.minIntrinsicWidth(cells, containerWidth);
if (!containerWidth.isFinite || columnCount < 1) return words;
return math.min(words, containerWidth / columnCount);
}
@override
double? flex(Iterable<RenderBox> cells) => null;
}
@@ -3,6 +3,7 @@ import 'package:flutter/widgets.dart';
import '../../../../../core/api_gateway.dart';
import '../../../../artifacts/ui/artifact_html_view.dart';
import '../../../files/files_viewer.dart';
import 'chat_shown_diff_card.dart';
import 'chat_shown_file_card.dart';
import 'chat_shown_html_card.dart';
import 'chat_shown_link_image.dart';
@@ -35,6 +36,7 @@ class ChatShownCard extends StatelessWidget {
return switch ('${item['kind']}') {
'notify' => ChatShownNotifyRow(item: item),
'html' => ChatShownHtmlCard(item: item, htmlBuilder: htmlBuilder),
'diff' => ChatShownDiffCard(item: item),
'image' when path.isEmpty => ChatShownLinkImage(
item: item,
openExternal: viewer.openExternal,
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';
import '../../../../../core/api_gateway.dart';
import '../../../../changes/changes.dart';
import '../../../domain/chat_shown_diff.dart';
import 'chat_shown_surface.dart';
/// How many changed files the card lists before "Show all".
const chatShownDiffPreviewFiles = 8;
/// A Git comparison the model showed through `show_diff`: what was compared,
/// the totals, an honest note when the size limits left something out, and
/// one row per changed file that opens the app's file diff viewer, stepping
/// through every file of the diff. A diff the server no longer retains says so.
class ChatShownDiffCard extends StatefulWidget {
const ChatShownDiffCard({super.key, required this.item});
final JsonMap item;
@override
State<ChatShownDiffCard> createState() => _ChatShownDiffCardState();
}
class _ChatShownDiffCardState extends State<ChatShownDiffCard> {
bool _all = false;
@override
Widget build(BuildContext context) {
final diff = ChatShownDiff.of(widget.item);
if (diff == null) return const SizedBox.shrink();
final title = chatShownTitle(widget.item, 'Diff');
final secondary = chatShownSecondary(context);
final noteStyle = Theme.of(
context,
).textTheme.bodySmall?.copyWith(color: secondary);
final capture = diff.capture;
final files = capture?.files ?? const <FileChange>[];
final shown = _all || files.length <= chatShownDiffPreviewFiles
? files
: files.take(chatShownDiffPreviewFiles).toList();
return ChatShownSurface(
label: 'Shown diff $title',
maxWidth: 720,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 4),
child: ChatShownHeading(
title: title,
subtitle: diff.comparison,
leading: Icon(Icons.difference_outlined, color: secondary),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 8),
child: ChangeStatText(
diff.heading,
key: const Key('chat-shown-diff-heading'),
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
if (capture == null)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 12),
child: Text('This diff is no longer retained', style: noteStyle),
)
else ...[
if (diff.partial)
Padding(
key: const Key('chat-shown-diff-partial'),
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 8),
child: Text(
capture.diagnostic.isEmpty
? 'Part of this diff was left out by the size limit.'
: 'Partial diff: ${capture.diagnostic}',
style: noteStyle,
),
),
for (final file in shown)
ChangeFileRow(
key: ValueKey<String>('chat-shown-diff-file-${file.path}'),
file: file,
onOpen: (file) =>
showFileDiffViewer(context, file, files: files),
),
if (shown.length < files.length)
Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(4, 0, 4, 4),
child: TextButton(
key: const Key('chat-shown-diff-all'),
onPressed: () => setState(() => _all = true),
child: Text('Show all ${files.length} files'),
),
),
),
if (capture.omitted > 0)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 0, 12, 12),
child: Text(
'${capture.omitted} more '
'${capture.omitted == 1 ? 'file is' : 'files are'} '
'not listed.',
style: noteStyle,
),
),
],
],
),
);
}
}