From 579eaeba88d3e86d635f991a964a0932b9c387bd Mon Sep 17 00:00:00 2001 From: Callum Moffat Date: Mon, 5 Jun 2023 02:35:44 -0400 Subject: [PATCH] Fix alignment of thumbnail with tall codespan --- lib/widgets/post_row.dart | 2 +- lib/widgets/post_spans.dart | 17 +++++++++++++++++ lib/widgets/thread_row.dart | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/widgets/post_row.dart b/lib/widgets/post_row.dart index cff8c8739..c59b9b38a 100644 --- a/lib/widgets/post_row.dart +++ b/lib/widgets/post_row.dart @@ -240,7 +240,7 @@ class PostRow extends StatelessWidget { if (attachments != null) WidgetSpan( child: attachments, floating: settings.imagesOnRight ? PlaceholderFloating.right : PlaceholderFloating.left, - alignment: PlaceholderAlignment.middle + alignment: latestPost.span.hasVeryTallWidgetSpan ? PlaceholderAlignment.top : PlaceholderAlignment.middle ), if ((!parentZone.tree || (post.parentId != latestPost.threadId && (baseOptions?.highlightString?.isNotEmpty ?? false))) && !site.explicitIds && post.parentId != null) ...[ PostQuoteLinkSpan( diff --git a/lib/widgets/post_spans.dart b/lib/widgets/post_spans.dart index 50dd82031..a8072c6f4 100644 --- a/lib/widgets/post_spans.dart +++ b/lib/widgets/post_spans.dart @@ -131,6 +131,7 @@ abstract class PostSpan { String buildText(); double estimateLines(double charactersPerLine) => buildText().length / charactersPerLine; bool get containsLink => false; + bool get hasVeryTallWidgetSpan => false; } class _PostWrapperSpan extends PostSpan { @@ -258,6 +259,16 @@ class PostNodeSpan extends PostSpan { @override bool get containsLink => children.any((c) => c.containsLink); + + @override + bool get hasVeryTallWidgetSpan { + for (final child in children) { + if (child.hasVeryTallWidgetSpan) { + return true; + } + } + return false; + } } class PostTextSpan extends PostSpan { @@ -759,6 +770,12 @@ class PostCodeSpan extends PostSpan { String buildText() { return '[code]$text[/code]'; } + + @override + bool get hasVeryTallWidgetSpan { + final lineCount = RegExp(r'\n').allMatches(text).length + 1; + return lineCount > 5; + } } class PostSpoilerSpan extends PostSpan { diff --git a/lib/widgets/thread_row.dart b/lib/widgets/thread_row.dart index 437c484ac..adb55248a 100644 --- a/lib/widgets/thread_row.dart +++ b/lib/widgets/thread_row.dart @@ -363,7 +363,7 @@ class ThreadRow extends StatelessWidget { if (site.classicCatalogStyle && attachments != null) WidgetSpan( child: attachments, floating: settings.imagesOnRight ? PlaceholderFloating.right : PlaceholderFloating.left, - alignment: PlaceholderAlignment.middle + alignment: latestThread.posts_.first.span.hasVeryTallWidgetSpan ? PlaceholderAlignment.top : PlaceholderAlignment.middle ), if (headerRow.isNotEmpty) TextSpan( children: [