-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content: Add start attribute support for ordered list #1329
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,48 @@ void main() { | |
}); | ||
}); | ||
|
||
group('ListNodeWidget', () { | ||
testWidgets('ordered list with custom start', (tester) async { | ||
await prepareContent(tester, plainContent('<ol start="3">\n<li>third</li>\n<li>fourth</li>\n</ol>')); | ||
|
||
expect(find.text('3. '), findsOneWidget); | ||
expect(find.text('4. '), findsOneWidget); | ||
expect(find.text('third'), findsOneWidget); | ||
expect(find.text('fourth'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('list uses correct text baseline alignment', (tester) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I guess this is good to check too but it's not the thing I was hoping for in #1329 (comment) — it doesn't check that #1356 was (and remains) fixed. In particular if I make this edit: --- lib/widgets/content.dart
+++ lib/widgets/content.dart
@@ -507,7 +507,7 @@ class ListNodeWidget extends StatelessWidget {
defaultVerticalAlignment: TableCellVerticalAlignment.baseline,
textBaseline: localizedTextBaseline(context),
columnWidths: const <int, TableColumnWidth>{
- 0: IntrinsicColumnWidth(),
+ 0: FixedColumnWidth(20),
1: FlexColumnWidth(),
}, then that should reintroduce #1356 — it'd make the new code behave pretty much just like the old code before your fix — but there isn't currently a test that would detect that and fail. Can you find a way to write a test that checks that #1356 is fixed? |
||
await prepareContent(tester, plainContent(ContentExample.orderedListLargeStart.html)); | ||
|
||
final table = tester.widget<Table>(find.byType(Table)); | ||
check(table.defaultVerticalAlignment).equals(TableCellVerticalAlignment.baseline); | ||
check(table.textBaseline).equals(localizedTextBaseline(tester.element(find.byType(Table)))); | ||
}); | ||
|
||
testWidgets('ordered list markers have enough space to render completely', (tester) async { | ||
await prepareContent(tester, plainContent(ContentExample.orderedListLargeStart.html)); | ||
|
||
final renderParagraph = tester.renderObject(find.textContaining('9999.')) as RenderParagraph; | ||
final textHeight = renderParagraph.size.height; | ||
final lineHeight = renderParagraph.text.style!.height! * renderParagraph.text.style!.fontSize!; | ||
check(textHeight).equals(lineHeight); | ||
check(renderParagraph.didExceedMaxLines).isFalse(); | ||
}); | ||
|
||
testWidgets('ordered list markers are end-aligned', (tester) async { | ||
await prepareContent(tester, plainContent(ContentExample.orderedListLargeStart.html)); | ||
|
||
final marker9999 = tester.renderObject(find.textContaining('9999.')) as RenderParagraph; | ||
final marker10000 = tester.renderObject(find.textContaining('10000.')) as RenderParagraph; | ||
check(marker9999.size.width != marker10000.size.width).isTrue(); | ||
|
||
final marker9999Pos = marker9999.localToGlobal(Offset.zero); | ||
final marker10000Pos = marker10000.localToGlobal(Offset.zero); | ||
check(marker9999Pos.dx + marker9999.size.width) | ||
.equals(marker10000Pos.dx + marker10000.size.width); | ||
}); | ||
}); | ||
|
||
group('Spoiler', () { | ||
testContentSmoke(ContentExample.spoilerDefaultHeader); | ||
testContentSmoke(ContentExample.spoilerPlainCustomHeader); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still have an assert for this method's expectations on
element.localName
.If you look at other methods on this class, you can see that that's the pattern they follow: any facts they assume (which their callers are expected to ensure), they assert at the top. And then down at the if/else below, this assumption is essential for understanding why the logic makes sense, so it's important to make explicit within the method.
(See also #1329 (comment) — this is why I said there that the references to ListStyle could switch to referring to
element.localName
directly, instead of saying they'd be deleted.)