Keep numbered lists counting across nested items and blank lines

A list ended at the first line that was not an item, so a numbered list
with nested bullets, wrapped lines or blank lines between items became
one-item lists that each showed 1. Lists now nest (an item holds the
blocks indented under it), continue across blank lines, join wrapped
lines, and number from their first item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 20:39:39 +00:00
parent dd742ec8e4
commit 99f7edc0ec
5 changed files with 253 additions and 27 deletions
@@ -199,7 +199,11 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
),
),
);
case MarkdownList(ordered: final ordered, items: final items):
case MarkdownList(
ordered: final ordered,
start: final start,
items: final items,
):
return Semantics(
container: true,
explicitChildNodes: true,
@@ -218,9 +222,9 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Text(ordered ? '${index + 1}.' : '•'),
child: Text(ordered ? '${start + index}.' : '•'),
),
Expanded(child: _text(context, items[index])),
Expanded(child: _listItem(context, items[index])),
],
),
),
@@ -279,6 +283,20 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
).end.clamp(0, widget.text.length);
}
/// An item's text and, under it, whatever is nested in it.
Widget _listItem(BuildContext context, MarkdownListItem item) {
if (item.children.isEmpty) return _text(context, item.text);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 4,
children: [
_text(context, item.text),
for (final child in item.children) _block(context, child),
],
);
}
Widget _cell(BuildContext context, String text, {bool header = false}) {
final style = header
? _roleStyle(context, Theme.of(context).textTheme.labelLarge)