[go: nahoru, domu]

Skip to content

Commit

Permalink
Remove RenderEditable textPainter height hack (#113301)
Browse files Browse the repository at this point in the history
* remove RenderEditable textPainter height hack

* Still applies the hack on web

* unskip web
  • Loading branch information
LongCatIsLooong committed Dec 13, 2022
1 parent b713edc commit 04ee592
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
13 changes: 1 addition & 12 deletions packages/flutter/lib/src/rendering/editable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 29 additions & 5 deletions packages/flutter/test/painting/text_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 04ee592

Please sign in to comment.