Skip to content

Commit

Permalink
Fix alignment of thumbnail with tall codespan
Browse files Browse the repository at this point in the history
  • Loading branch information
moffatman committed Jun 25, 2023
1 parent 5e1028b commit 579eaeb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/post_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 17 additions & 0 deletions lib/widgets/post_spans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/thread_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 579eaeb

Please sign in to comment.