Skip to content

Commit 04ee592

Browse files
Remove RenderEditable textPainter height hack (#113301)
* remove RenderEditable textPainter height hack * Still applies the hack on web * unskip web
1 parent b713edc commit 04ee592

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

packages/flutter/lib/src/rendering/editable.dart

+1-12
Original file line numberDiff line numberDiff line change
@@ -1878,21 +1878,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
18781878
return math.max(estimatedHeight, minHeight);
18791879
}
18801880

1881-
// TODO(LongCatIsLooong): this is a workaround for
1882-
// https://github.com/flutter/flutter/issues/112123.
1883-
// Use preferredLineHeight since SkParagraph currently returns an incorrect
1884-
// height.
1885-
final TextHeightBehavior? textHeightBehavior = this.textHeightBehavior;
1886-
final bool usePreferredLineHeightHack = maxLines == 1
1887-
&& text?.codeUnitAt(0) == null
1888-
&& strutStyle != null && strutStyle != StrutStyle.disabled
1889-
&& textHeightBehavior != null
1890-
&& (!textHeightBehavior.applyHeightToFirstAscent || !textHeightBehavior.applyHeightToLastDescent);
1891-
18921881
// Special case maxLines == 1 since it forces the scrollable direction
18931882
// to be horizontal. Report the real height to prevent the text from being
18941883
// clipped.
1895-
if (maxLines == 1 && !usePreferredLineHeightHack) {
1884+
if (maxLines == 1) {
18961885
// The _layoutText call lays out the paragraph using infinite width when
18971886
// maxLines == 1. Also _textPainter.maxLines will be set to 1 so should
18981887
// there be any line breaks only the first line is shown.

packages/flutter/test/painting/text_painter_test.dart

+29-5
Original file line numberDiff line numberDiff line change
@@ -1217,12 +1217,36 @@ void main() {
12171217
textDirection: TextDirection.ltr,
12181218
);
12191219

1220-
textPainter.layout();
1221-
expect(
1222-
textPainter.getWordBoundary(const TextPosition(offset: 8)),
1223-
const TextRange(start: 8, end: 16),
1220+
textPainter.layout();
1221+
expect(
1222+
textPainter.getWordBoundary(const TextPosition(offset: 8)),
1223+
const TextRange(start: 8, end: 16),
1224+
);
1225+
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61017
1226+
1227+
test('TextHeightBehavior with strut on empty paragraph', () {
1228+
// Regression test for https://github.com/flutter/flutter/issues/112123
1229+
const TextStyle style = TextStyle(height: 11, fontSize: 7);
1230+
const TextSpan simple = TextSpan(text: 'x', style: style);
1231+
const TextSpan emptyString = TextSpan(text: '', style: style);
1232+
const TextSpan emptyParagraph = TextSpan(style: style);
1233+
1234+
final TextPainter painter = TextPainter(
1235+
textDirection: TextDirection.ltr,
1236+
strutStyle: StrutStyle.fromTextStyle(style, forceStrutHeight: true),
1237+
textHeightBehavior: const TextHeightBehavior(applyHeightToFirstAscent: false, applyHeightToLastDescent: false),
12241238
);
1225-
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61017
1239+
1240+
painter.text = simple;
1241+
painter.layout();
1242+
final double height = painter.height;
1243+
for (final TextSpan span in <TextSpan>[simple, emptyString, emptyParagraph]) {
1244+
painter.text = span;
1245+
painter.layout();
1246+
expect(painter.height, height, reason: '$span is expected to have a height of $height');
1247+
expect(painter.preferredLineHeight, height, reason: '$span is expected to have a height of $height');
1248+
}
1249+
});
12261250

12271251
test('TextPainter plainText getter', () {
12281252
final TextPainter painter = TextPainter()

0 commit comments

Comments
 (0)