Skip to content

Commit 04f2e04

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 5285d99 commit 04f2e04

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
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(topEm: false, marginLeftEm: false),
350+
text: null,
351+
nodes: _parseChildSpans(otherSpans))])]);
352+
} else {
353+
innerSpanNode = KatexSpanNode(
354+
styles: styles.filter(topEm: false),
355+
text: null,
356+
nodes: _parseChildSpans(otherSpans));
354357
}
355358

356359
rows.add(KatexVlistRowNode(

test/model/content_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,10 +2486,7 @@ void main() async {
24862486
testParseExample(ContentExample.mathBlockKatexSubSuperScript);
24872487
testParseExample(ContentExample.mathBlockKatexRaisebox);
24882488
testParseExample(ContentExample.mathBlockKatexNegativeMargins);
2489-
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow,
2490-
// TODO fix parser to filter negative margins styles from
2491-
// vlist row span styles.
2492-
skip: true);
2489+
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow);
24932490

24942491
testParseExample(ContentExample.imageSingle);
24952492
testParseExample(ContentExample.imageSingleNoDimensions);

0 commit comments

Comments
 (0)