Unverified Commit 04ee5926 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove RenderEditable textPainter height hack (#113301)

* remove RenderEditable textPainter height hack

* Still applies the hack on web

* unskip web
parent b713edce
......@@ -1878,21 +1878,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
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.
......
......@@ -1217,12 +1217,36 @@ void main() {
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()
......
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