Remove RenderEditable textPainter height hack (#113301)
* remove RenderEditable textPainter height hack
* Still applies the hack on web
* unskip web
diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart
index cc06f96..d6fad8c 100644
--- a/packages/flutter/lib/src/rendering/editable.dart
+++ b/packages/flutter/lib/src/rendering/editable.dart
@@ -1878,21 +1878,10 @@
return math.max(estimatedHeight, minHeight);
}
- // TODO(LongCatIsLooong): this is a workaround for
- // https://github.com/flutter/flutter/issues/112123.
- // Use preferredLineHeight since SkParagraph currently returns an incorrect
- // height.
- final TextHeightBehavior? textHeightBehavior = this.textHeightBehavior;
- final bool usePreferredLineHeightHack = maxLines == 1
- && text?.codeUnitAt(0) == null
- && strutStyle != null && strutStyle != StrutStyle.disabled
- && textHeightBehavior != null
- && (!textHeightBehavior.applyHeightToFirstAscent || !textHeightBehavior.applyHeightToLastDescent);
-
// Special case maxLines == 1 since it forces the scrollable direction
// to be horizontal. Report the real height to prevent the text from being
// clipped.
- if (maxLines == 1 && !usePreferredLineHeightHack) {
+ if (maxLines == 1) {
// The _layoutText call lays out the paragraph using infinite width when
// maxLines == 1. Also _textPainter.maxLines will be set to 1 so should
// there be any line breaks only the first line is shown.
diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart
index f4831e3..9c890b4 100644
--- a/packages/flutter/test/painting/text_painter_test.dart
+++ b/packages/flutter/test/painting/text_painter_test.dart
@@ -1217,12 +1217,36 @@
textDirection: TextDirection.ltr,
);
- textPainter.layout();
- expect(
- textPainter.getWordBoundary(const TextPosition(offset: 8)),
- const TextRange(start: 8, end: 16),
+ textPainter.layout();
+ expect(
+ textPainter.getWordBoundary(const TextPosition(offset: 8)),
+ const TextRange(start: 8, end: 16),
+ );
+ }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61017
+
+ test('TextHeightBehavior with strut on empty paragraph', () {
+ // Regression test for https://github.com/flutter/flutter/issues/112123
+ const TextStyle style = TextStyle(height: 11, fontSize: 7);
+ const TextSpan simple = TextSpan(text: 'x', style: style);
+ const TextSpan emptyString = TextSpan(text: '', style: style);
+ const TextSpan emptyParagraph = TextSpan(style: style);
+
+ final TextPainter painter = TextPainter(
+ textDirection: TextDirection.ltr,
+ strutStyle: StrutStyle.fromTextStyle(style, forceStrutHeight: true),
+ textHeightBehavior: const TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false),
);
- }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61017
+
+ painter.text = simple;
+ painter.layout();
+ final double height = painter.height;
+ for (final TextSpan span in <TextSpan>[simple, emptyString, emptyParagraph]) {
+ painter.text = span;
+ painter.layout();
+ expect(painter.height, height, reason: '$span is expected to have a height of $height');
+ expect(painter.preferredLineHeight, height, reason: '$span is expected to have a height of $height');
+ }
+ });
test('TextPainter plainText getter', () {
final TextPainter painter = TextPainter()