Unverified Commit b9908f6b authored by chunhtai's avatar chunhtai Committed by GitHub

Fixes renderparagraph crashes due to truncated semantics node (#88190)

* Fixes renderparagraph crashes due to truncated semantics node

* add period
parent c6b8bf9a
...@@ -2814,6 +2814,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ...@@ -2814,6 +2814,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) { children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) {
final SemanticsNode childNode = children.elementAt(childIndex); final SemanticsNode childNode = children.elementAt(childIndex);
final TextParentData parentData = child!.parentData! as TextParentData; final TextParentData parentData = child!.parentData! as TextParentData;
assert(parentData.scale != null);
childNode.rect = Rect.fromLTWH( childNode.rect = Rect.fromLTWH(
childNode.rect.left, childNode.rect.left,
childNode.rect.top, childNode.rect.top,
......
...@@ -933,13 +933,17 @@ class RenderParagraph extends RenderBox ...@@ -933,13 +933,17 @@ class RenderParagraph extends RenderBox
children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) { children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) {
final SemanticsNode childNode = children.elementAt(childIndex); final SemanticsNode childNode = children.elementAt(childIndex);
final TextParentData parentData = child!.parentData! as TextParentData; final TextParentData parentData = child!.parentData! as TextParentData;
childNode.rect = Rect.fromLTWH( assert(parentData.scale != null || parentData.offset == Offset.zero);
childNode.rect.left, // parentData.scale may be null if the render object is truncated.
childNode.rect.top, if (parentData.scale != null) {
childNode.rect.width * parentData.scale!, childNode.rect = Rect.fromLTWH(
childNode.rect.height * parentData.scale!, childNode.rect.left,
); childNode.rect.top,
newChildren.add(childNode); childNode.rect.width * parentData.scale!,
childNode.rect.height * parentData.scale!,
);
newChildren.add(childNode);
}
childIndex += 1; childIndex += 1;
} }
child = childAfter(child!); child = childAfter(child!);
......
...@@ -702,7 +702,40 @@ void main() { ...@@ -702,7 +702,40 @@ void main() {
expect(boxes[8], const TextBox.fromLTRBD(14.0, 28.0, 28.0, 42.0 , TextDirection.ltr)); expect(boxes[8], const TextBox.fromLTRBD(14.0, 28.0, 28.0, 42.0 , TextDirection.ltr));
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020 }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020
test('Supports gesture recognizer semantics', () { test('Does not include the semantics node of truncated rendering children', () {
// Regression test for https://github.com/flutter/flutter/issues/88180
const double screenWidth = 100;
const String sentence = 'truncated';
final List<RenderBox> renderBoxes = <RenderBox>[
RenderParagraph(
const TextSpan(text: sentence), textDirection: TextDirection.ltr),
];
final RenderParagraph paragraph = RenderParagraph(
const TextSpan(
text: 'a long line to be truncated.',
children: <InlineSpan>[
WidgetSpan(child: Text(sentence)),
],
),
overflow: TextOverflow.ellipsis,
textScaleFactor: 1.0,
children: renderBoxes,
textDirection: TextDirection.ltr,
);
layout(paragraph, constraints: const BoxConstraints(maxWidth: screenWidth));
final SemanticsNode result = SemanticsNode();
final SemanticsNode truncatedChild = SemanticsNode();
truncatedChild.tags = <SemanticsTag>{const PlaceholderSpanIndexSemanticsTag(0)};
paragraph.assembleSemanticsNode(result, SemanticsConfiguration(), <SemanticsNode>[truncatedChild]);
// It should only contain the semantics node of the TextSpan.
expect(result.childrenCount, 1);
result.visitChildren((SemanticsNode node) {
expect(node != truncatedChild, isTrue);
return true;
});
});
test('Supports gesture recognizer semantics', () {
final RenderParagraph paragraph = RenderParagraph( final RenderParagraph paragraph = RenderParagraph(
TextSpan(text: _kText, children: <InlineSpan>[ TextSpan(text: _kText, children: <InlineSpan>[
TextSpan(text: 'one', recognizer: TapGestureRecognizer()..onTap = () {}), TextSpan(text: 'one', recognizer: TapGestureRecognizer()..onTap = () {}),
......
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