Unverified Commit 6c70a8fe authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Fix right alignment TWB longestLine (#54234)

Fixes an alignment bug seen when using both TextWidthBasis.longestLine and TextAlign.right.
parent 0b9c42f9
......@@ -564,7 +564,7 @@ class TextPainter {
_paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
if (minWidth != maxWidth) {
final double newWidth = maxIntrinsicWidth.clamp(minWidth, maxWidth) as double;
if (newWidth != width) {
if (newWidth != _applyFloatingPointHack(_paragraph.width)) {
_paragraph.layout(ui.ParagraphConstraints(width: newWidth));
}
}
......
......@@ -800,6 +800,56 @@ void main() {
expect(textSizeLongestLine.height, equals(fontHeight * 2));
}, skip: isBrowser); // TODO(yjbanov): https://github.com/flutter/flutter/issues/44020
testWidgets('textWidthBasis with textAlign still obeys parent alignment', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: const <Widget>[
Text(
'LEFT ALIGNED, PARENT',
textAlign: TextAlign.left,
textWidthBasis: TextWidthBasis.parent,
),
Text(
'RIGHT ALIGNED, PARENT',
textAlign: TextAlign.right,
textWidthBasis: TextWidthBasis.parent,
),
Text(
'LEFT ALIGNED, LONGEST LINE',
textAlign: TextAlign.left,
textWidthBasis: TextWidthBasis.longestLine,
),
Text(
'RIGHT ALIGNED, LONGEST LINE',
textAlign: TextAlign.right,
textWidthBasis: TextWidthBasis.longestLine,
),
],
),
),
),
),
);
// All Texts have the same horizontal alignment.
final double offsetX = tester.getTopLeft(find.text('LEFT ALIGNED, PARENT')).dx;
expect(tester.getTopLeft(find.text('RIGHT ALIGNED, PARENT')).dx, equals(offsetX));
expect(tester.getTopLeft(find.text('LEFT ALIGNED, LONGEST LINE')).dx, equals(offsetX));
expect(tester.getTopLeft(find.text('RIGHT ALIGNED, LONGEST LINE')).dx, equals(offsetX));
// All Texts are less than or equal to the width of the Column.
final double width = tester.getSize(find.byType(Column)).width;
expect(tester.getSize(find.text('LEFT ALIGNED, PARENT')).width, lessThan(width));
expect(tester.getSize(find.text('RIGHT ALIGNED, PARENT')).width, lessThan(width));
expect(tester.getSize(find.text('LEFT ALIGNED, LONGEST LINE')).width, lessThan(width));
expect(tester.getSize(find.text('RIGHT ALIGNED, LONGEST LINE')).width, equals(width));
}, skip: isBrowser); // TODO(yjbanov): https://github.com/flutter/flutter/issues/44020
testWidgets('Paragraph.getBoxesForRange returns nothing when selection range is zero length', (WidgetTester tester) async {
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle());
builder.addText('hello');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment