File tree 3 files changed +34
-1
lines changed 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -599,6 +599,15 @@ class TextPainter {
599
599
return _paragraph! .didExceedMaxLines;
600
600
}
601
601
602
+ /// The distance from the left edge of the leftmost glyph to the right edge of
603
+ /// the rightmost glyph in the paragraph.
604
+ ///
605
+ /// Valid only after [layout] has been called.
606
+ double get longestLine {
607
+ assert (! _debugNeedsLayout);
608
+ return _paragraph! .longestLine;
609
+ }
610
+
602
611
double ? _lastMinWidth;
603
612
double ? _lastMaxWidth;
604
613
Original file line number Diff line number Diff line change @@ -630,6 +630,12 @@ class RenderParagraph extends RenderBox
630
630
@visibleForTesting
631
631
bool get debugHasOverflowShader => _overflowShader != null ;
632
632
633
+ /// Whether this paragraph currently has overflow and needs clipping.
634
+ ///
635
+ /// Used to test this object. Not for use in production.
636
+ @visibleForTesting
637
+ bool get debugNeedsClipping => _needsClipping;
638
+
633
639
void _layoutText ({ double minWidth = 0.0 , double maxWidth = double .infinity }) {
634
640
final bool widthMatters = softWrap || overflow == TextOverflow .ellipsis;
635
641
_textPainter.layout (
@@ -781,7 +787,7 @@ class RenderParagraph extends RenderBox
781
787
size = constraints.constrain (textSize);
782
788
783
789
final bool didOverflowHeight = size.height < textSize.height || textDidExceedMaxLines;
784
- final bool didOverflowWidth = size.width < textSize.width;
790
+ final bool didOverflowWidth = size.width < textSize.width || size.width < _textPainter.longestLine ;
785
791
// TODO(abarth): We're only measuring the sizes of the line boxes here. If
786
792
// the glyphs draw outside the line boxes, we might think that there isn't
787
793
// visual overflow when there actually is visual overflow. This can become
Original file line number Diff line number Diff line change @@ -326,6 +326,24 @@ void main() {
326
326
expect (paragraph.debugHasOverflowShader, isFalse);
327
327
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61018
328
328
329
+ test ('one character clip test' , () {
330
+ // Regressing test for https://github.com/flutter/flutter/issues/99140
331
+ final RenderParagraph paragraph = RenderParagraph (
332
+ const TextSpan (
333
+ text: '7' ,
334
+ style: TextStyle (fontFamily: 'Ahem' , fontSize: 60.0 ),
335
+ ),
336
+ textDirection: TextDirection .ltr,
337
+ maxLines: 1 ,
338
+ );
339
+
340
+ // Lay out in a narrow box to force clipping.
341
+ // The text width is 60 bigger than the constraints width.
342
+ layout (paragraph, constraints: BoxConstraints .tight (const Size (50.0 , 200.0 )));
343
+
344
+ expect (paragraph.debugNeedsClipping, true );
345
+ }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61018
346
+
329
347
test ('maxLines' , () {
330
348
final RenderParagraph paragraph = RenderParagraph (
331
349
const TextSpan (
You can’t perform that action at this time.
0 commit comments