Unverified Commit 878fe20a authored by chunhtai's avatar chunhtai Committed by GitHub

fix widgetspan does not work with ellipsis in text widget (#38699)

parent 109893c6
......@@ -513,7 +513,7 @@ class RenderParagraph extends RenderBox
void _setParentData() {
RenderBox child = firstChild;
int childIndex = 0;
while (child != null) {
while (child != null && childIndex < _textPainter.inlinePlaceholderBoxes.length) {
final TextParentData textParentData = child.parentData;
textParentData.offset = Offset(
_textPainter.inlinePlaceholderBoxes[childIndex].left,
......@@ -640,8 +640,11 @@ class RenderParagraph extends RenderBox
RenderBox child = firstChild;
int childIndex = 0;
while (child != null) {
assert(childIndex < _textPainter.inlinePlaceholderBoxes.length);
// childIndex might be out of index of placeholder boxes. This can happen
// if engine truncates children due to ellipsis. Sadly, we would not know
// it until we finish layout, and RenderObject is in immutable state at
// this point.
while (child != null && childIndex < _textPainter.inlinePlaceholderBoxes.length) {
final TextParentData textParentData = child.parentData;
final double scale = textParentData.scale;
......
......@@ -116,6 +116,37 @@ void main() {
expect(text.text.style.fontSize, 20.0);
});
testWidgets('inline widgets works with ellipsis', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/35869
const TextStyle textStyle = TextStyle(fontFamily: 'Ahem');
await tester.pumpWidget(
Text.rich(
TextSpan(
children: <InlineSpan>[
const TextSpan(text: 'a very very very very very very very very very very long line'),
WidgetSpan(
child: SizedBox(
width: 20,
height: 40,
child: Card(
child: RichText(
text: const TextSpan(text: 'widget should be truncated'),
textDirection: TextDirection.rtl,
),
),
),
),
],
style: textStyle,
),
textDirection: TextDirection.ltr,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
);
expect(tester.takeException(), null);
});
testWidgets('semanticsLabel can override text label', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
......
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