Fixes renderparagraph crashes due to truncated semantics node (#88190)
* Fixes renderparagraph crashes due to truncated semantics node * add period
This commit is contained in:
@@ -2814,6 +2814,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) {
|
||||
final SemanticsNode childNode = children.elementAt(childIndex);
|
||||
final TextParentData parentData = child!.parentData! as TextParentData;
|
||||
assert(parentData.scale != null);
|
||||
childNode.rect = Rect.fromLTWH(
|
||||
childNode.rect.left,
|
||||
childNode.rect.top,
|
||||
|
||||
@@ -933,13 +933,17 @@ class RenderParagraph extends RenderBox
|
||||
children.elementAt(childIndex).isTagged(PlaceholderSpanIndexSemanticsTag(placeholderIndex))) {
|
||||
final SemanticsNode childNode = children.elementAt(childIndex);
|
||||
final TextParentData parentData = child!.parentData! as TextParentData;
|
||||
childNode.rect = Rect.fromLTWH(
|
||||
childNode.rect.left,
|
||||
childNode.rect.top,
|
||||
childNode.rect.width * parentData.scale!,
|
||||
childNode.rect.height * parentData.scale!,
|
||||
);
|
||||
newChildren.add(childNode);
|
||||
assert(parentData.scale != null || parentData.offset == Offset.zero);
|
||||
// parentData.scale may be null if the render object is truncated.
|
||||
if (parentData.scale != null) {
|
||||
childNode.rect = Rect.fromLTWH(
|
||||
childNode.rect.left,
|
||||
childNode.rect.top,
|
||||
childNode.rect.width * parentData.scale!,
|
||||
childNode.rect.height * parentData.scale!,
|
||||
);
|
||||
newChildren.add(childNode);
|
||||
}
|
||||
childIndex += 1;
|
||||
}
|
||||
child = childAfter(child!);
|
||||
|
||||
@@ -702,7 +702,40 @@ void main() {
|
||||
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
|
||||
|
||||
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(
|
||||
TextSpan(text: _kText, children: <InlineSpan>[
|
||||
TextSpan(text: 'one', recognizer: TapGestureRecognizer()..onTap = () {}),
|
||||
|
||||
Reference in New Issue
Block a user