Skip to content

Commit cc17284

Browse files
content: Filter negative margin styles if present on a vlist row
This fixes a bug where if negative margin on a vlist row is present the widget side code would hit an assert. Displaying the error (red screen) in debug mode, but in release mode the negative padding would be applied twice, once by `_KatexNegativeMargin` and another by `Padding` widget.
1 parent 4ad7f83 commit cc17284

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

lib/model/katex.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ class _KatexParser {
332332
}
333333
final pstrutHeight = pstrutStyles.heightEm ?? 0;
334334

335-
KatexSpanNode innerSpanNode = KatexSpanNode(
336-
styles: styles,
337-
text: null,
338-
nodes: _parseChildSpans(otherSpans));
335+
final KatexSpanNode innerSpanNode;
339336

340337
final marginRightEm = styles.marginRightEm;
341338
final marginLeftEm = styles.marginLeftEm;
@@ -346,11 +343,17 @@ class _KatexParser {
346343
innerSpanNode = KatexSpanNode(
347344
styles: KatexSpanStyles(),
348345
text: null,
349-
nodes: [
350-
KatexNegativeMarginNode(
351-
leftOffsetEm: marginLeftEm,
352-
nodes: [innerSpanNode]),
353-
]);
346+
nodes: [KatexNegativeMarginNode(
347+
leftOffsetEm: marginLeftEm,
348+
nodes: [KatexSpanNode(
349+
styles: styles.filter(marginLeftEm: false),
350+
text: null,
351+
nodes: _parseChildSpans(otherSpans))])]);
352+
} else {
353+
innerSpanNode = KatexSpanNode(
354+
styles: styles,
355+
text: null,
356+
nodes: _parseChildSpans(otherSpans));
354357
}
355358

356359
rows.add(KatexVlistRowNode(

test/model/content_test.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,7 @@ class ContentExample {
13211321
node: KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
13221322
KatexNegativeMarginNode(leftOffsetEm: -0.0785, nodes: [
13231323
KatexSpanNode(
1324-
styles: KatexSpanStyles(
1325-
marginRightEm: 0.05,
1326-
// TODO parser should not emit this `marginLeftEm` here because
1327-
// it already generates `KatexNegativeMarginNode` for handling it.
1328-
marginLeftEm: -0.0785),
1324+
styles: KatexSpanStyles(marginRightEm: 0.05),
13291325
text: null, nodes: [
13301326
KatexSpanNode(
13311327
styles: KatexSpanStyles(fontSizeEm: 0.7), // .reset-size6.size3

test/widgets/content_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,7 @@ void main() {
630630
('E', Offset(31.63, 14.52), Size(14.0, 25.0)),
631631
('X', Offset(43.06, 9.85), Size(15.42, 25.0)),
632632
]),
633-
// TODO re-enable this test when parser fixes a bug where
634-
// it emits negative margin in styles, allowing widget
635-
// code to hit an assert.
636-
(ContentExample.mathBlockKatexNegativeMarginsOnVlistRow, skip: true, [
633+
(ContentExample.mathBlockKatexNegativeMarginsOnVlistRow, skip: false, [
637634
('X', Offset(0.00, 7.04), Size(17.03, 25.00)),
638635
('n', Offset(17.03, 15.90), Size(8.63, 17.00)),
639636
]),

0 commit comments

Comments
 (0)