From 76cdef252332fe349d764f5649bf85674a959449 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 25 Jan 2024 13:05:51 +0000 Subject: [PATCH] content: Combine clusters of images in parseImplicitParagraphBlockContentList --- lib/model/content.dart | 13 ++++++++++++- lib/widgets/content.dart | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/model/content.dart b/lib/model/content.dart index 1af059ff358..5be052a1e2b 100644 --- a/lib/model/content.dart +++ b/lib/model/content.dart @@ -998,6 +998,7 @@ class _ZulipContentParser { assert(_debugParserContext == _ParserContext.block); final List result = []; final List currentParagraph = []; + List imageNodes = []; void consumeParagraph() { final parsed = parseBlockInline(currentParagraph); result.add(ParagraphNode( @@ -1015,9 +1016,19 @@ class _ZulipContentParser { continue; } if (currentParagraph.isNotEmpty) consumeParagraph(); - result.add(parseBlockContent(node)); + final block = parseBlockContent(node); + if (block is ImageNode) { + imageNodes.add(block); + continue; + } + if (imageNodes.isNotEmpty) { + result.add(ImageNodeList(imageNodes)); + imageNodes = []; + } + result.add(block); } if (currentParagraph.isNotEmpty) consumeParagraph(); + if (imageNodes.isNotEmpty) result.add(ImageNodeList(imageNodes)); return result; } diff --git a/lib/widgets/content.dart b/lib/widgets/content.dart index cf27cf88811..2a6fb97df11 100644 --- a/lib/widgets/content.dart +++ b/lib/widgets/content.dart @@ -85,6 +85,10 @@ class BlockContentList extends StatelessWidget { } else if (node is ImageNodeList) { return MessageImageList(node: node); } else if (node is ImageNode) { + assert(false, + "[ImageNode] not allowed in [BlockContentList]. " + "It should be wrapped in [ImageNodeList]." + ); return MessageImage(node: node); } else if (node is UnimplementedBlockContentNode) { return Text.rich(_errorUnimplemented(node));