@@ -628,18 +628,22 @@ class _InlineContentBuilder {
628
628
return _buildInlineCode (node);
629
629
} else if (node is UserMentionNode ) {
630
630
return WidgetSpan (alignment: PlaceholderAlignment .middle,
631
- child: UserMention (node: node));
631
+ child: UserMention (node: node, surroundingTextStyle : widget.style ));
632
632
} else if (node is UnicodeEmojiNode ) {
633
633
return TextSpan (text: node.emojiUnicode, recognizer: _recognizer);
634
634
} else if (node is ImageEmojiNode ) {
635
635
return WidgetSpan (alignment: PlaceholderAlignment .middle,
636
636
child: MessageImageEmoji (node: node));
637
637
} else if (node is MathInlineNode ) {
638
- return TextSpan (style: _kInlineMathStyle,
638
+ assert (widget.style.fontSize != null );
639
+ return TextSpan (
640
+ style: widget.style
641
+ .merge (_kInlineMathStyle)
642
+ .apply (fontSizeFactor: _kInlineCodeFontSizeFactor),
639
643
children: [TextSpan (text: node.texSource)]);
640
644
} else if (node is GlobalTimeNode ) {
641
645
return WidgetSpan (alignment: PlaceholderAlignment .middle,
642
- child: GlobalTime (node: node));
646
+ child: GlobalTime (node: node, surroundingTextStyle : widget.style ));
643
647
} else if (node is UnimplementedInlineContentNode ) {
644
648
return _errorUnimplemented (node);
645
649
} else {
@@ -688,8 +692,14 @@ class _InlineContentBuilder {
688
692
689
693
// TODO `code`: find equivalent of web's `unicode-bidi: embed; direction: ltr`
690
694
691
- // Use a light gray background, instead of a border.
692
- return _buildNodes (style: _kInlineCodeStyle, node.nodes);
695
+ assert (widget.style.fontSize != null );
696
+ return _buildNodes (
697
+ // Use a light gray background, instead of a border.
698
+ style: widget.style
699
+ .merge (_kInlineCodeStyle)
700
+ .apply (fontSizeFactor: _kInlineCodeFontSizeFactor),
701
+ node.nodes,
702
+ );
693
703
694
704
// Another fun solution -- we can in fact have a border! Like so:
695
705
// TextStyle(
@@ -709,17 +719,27 @@ class _InlineContentBuilder {
709
719
}
710
720
}
711
721
722
+ /// The [TextStyle] for inline math, excluding font-size adjustment.
723
+ ///
724
+ /// Inline math should use this and also apply [_kInlineCodeFontSizeFactor]
725
+ /// to the font size of the surrounding text
726
+ /// (which might be a Paragraph, a Heading, etc.).
712
727
final _kInlineMathStyle = _kInlineCodeStyle.merge (TextStyle (
713
728
backgroundColor: const HSLColor .fromAHSL (1 , 240 , 0.4 , 0.93 ).toColor ()));
714
729
730
+ const _kInlineCodeFontSizeFactor = 0.825 ;
731
+
732
+ /// The [TextStyle] for inline code, excluding font-size adjustment.
733
+ ///
734
+ /// Inline code should use this and also apply [_kInlineCodeFontSizeFactor]
735
+ /// to the font size of the surrounding text
736
+ /// (which might be a Paragraph, a Heading, etc.).
715
737
// Even though [kMonospaceTextStyle] is a variable-weight font,
716
738
// it's acceptable to skip [weightVariableTextStyle] here,
717
739
// assuming the text gets the effect of [weightVariableTextStyle]
718
740
// through inheritance, e.g., from a [DefaultTextStyle].
719
741
final _kInlineCodeStyle = kMonospaceTextStyle
720
- .merge (const TextStyle (
721
- backgroundColor: Color (0xffeeeeee ),
722
- fontSize: 0.825 * kBaseFontSize));
742
+ .merge (const TextStyle (backgroundColor: Color (0xffeeeeee )));
723
743
724
744
final _kCodeBlockStyle = kMonospaceTextStyle
725
745
.merge (const TextStyle (
@@ -750,9 +770,14 @@ final _kCodeBlockStyle = kMonospaceTextStyle
750
770
// const _kInlineCodeRightBracket = '⟩';
751
771
752
772
class UserMention extends StatelessWidget {
753
- const UserMention ({super .key, required this .node});
773
+ const UserMention ({
774
+ super .key,
775
+ required this .node,
776
+ required this .surroundingTextStyle,
777
+ });
754
778
755
779
final UserMentionNode node;
780
+ final TextStyle surroundingTextStyle;
756
781
757
782
@override
758
783
Widget build (BuildContext context) {
@@ -765,7 +790,7 @@ class UserMention extends StatelessWidget {
765
790
// One hopes an @-mention can't contain an embedded link.
766
791
// (The parser on creating a UserMentionNode has a TODO to check that.)
767
792
linkRecognizers: null ,
768
- style: Paragraph .textStyle ,
793
+ style: surroundingTextStyle ,
769
794
nodes: node.nodes));
770
795
}
771
796
@@ -832,9 +857,14 @@ class MessageImageEmoji extends StatelessWidget {
832
857
}
833
858
834
859
class GlobalTime extends StatelessWidget {
835
- const GlobalTime ({super .key, required this .node});
860
+ const GlobalTime ({
861
+ super .key,
862
+ required this .node,
863
+ required this .surroundingTextStyle,
864
+ });
836
865
837
866
final GlobalTimeNode node;
867
+ final TextStyle surroundingTextStyle;
838
868
839
869
static final _backgroundColor = const HSLColor .fromAHSL (1 , 0 , 0 , 0.93 ).toColor ();
840
870
static final _borderColor = const HSLColor .fromAHSL (1 , 0 , 0 , 0.8 ).toColor ();
@@ -861,7 +891,7 @@ class GlobalTime extends StatelessWidget {
861
891
// Ad-hoc spacing adjustment per feedback:
862
892
// https://chat.zulip.org/#narrow/stream/101-design/topic/clock.20icons/near/1729345
863
893
const SizedBox (width: 1 ),
864
- Text (text, style: Paragraph .textStyle ),
894
+ Text (text, style: surroundingTextStyle ),
865
895
]))));
866
896
}
867
897
}
0 commit comments