Skip to content

Commit 134b091

Browse files
katex: Wrap KaTeXWidget and KatexVlistNode in IntrinsicWidth
Ensures overline and underline widths match their child’s width instead of expanding to 100% of the container.
1 parent 3d3b1c1 commit 134b091

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/widgets/katex.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ class KatexWidget extends StatelessWidget {
4242
Widget build(BuildContext context) {
4343
Widget widget = _KatexNodeList(nodes: nodes);
4444

45-
return Directionality(
46-
textDirection: TextDirection.ltr,
47-
child: DefaultTextStyle(
48-
style: mkBaseKatexTextStyle(textStyle).copyWith(
49-
color: ContentTheme.of(context).textStylePlainParagraph.color),
50-
child: widget));
45+
return IntrinsicWidth(
46+
child: Directionality(
47+
textDirection: TextDirection.ltr,
48+
child: DefaultTextStyle(
49+
style: mkBaseKatexTextStyle(textStyle).copyWith(
50+
color: ContentTheme.of(context).textStylePlainParagraph.color),
51+
child: widget)),
52+
);
5153
}
5254
}
5355

@@ -232,11 +234,13 @@ class _KatexVlist extends StatelessWidget {
232234
Widget build(BuildContext context) {
233235
final em = DefaultTextStyle.of(context).style.fontSize!;
234236

235-
return Stack(children: List.unmodifiable(node.rows.map((row) {
236-
return Transform.translate(
237-
offset: Offset(0, row.verticalOffsetEm * em),
238-
child: _KatexSpan(row.node));
239-
})));
237+
return IntrinsicWidth(
238+
child: Stack(children: List.unmodifiable(node.rows.map((row) {
239+
return Transform.translate(
240+
offset: Offset(0, row.verticalOffsetEm * em),
241+
child: _KatexSpan(row.node));
242+
}))),
243+
);
240244
}
241245
}
242246

0 commit comments

Comments
 (0)