Skip to content

Commit

Permalink
[flutter] elide semantic information from certain widget spans (flutt…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Sep 16, 2020
1 parent a48e143 commit 13fcedc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/flutter/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -918,16 +918,18 @@ class RenderParagraph extends RenderBox
);

if (info.isPlaceholder) {
final SemanticsNode childNode = children.elementAt(placeholderIndex++);
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);
child = childAfter(child);
if (children.isNotEmpty) {
final SemanticsNode childNode = children.elementAt(placeholderIndex++);
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);
child = childAfter(child);
}
} else {
final SemanticsConfiguration configuration = SemanticsConfiguration()
..sortKey = OrdinalSortKey(ordinal++)
Expand Down
47 changes: 47 additions & 0 deletions packages/flutter/test/widgets/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,53 @@ void main() {
paragraph.layout(const ui.ParagraphConstraints(width: 1000));
expect(paragraph.getBoxesForRange(2, 2), isEmpty);
});

// Regression test for https://github.com/flutter/flutter/issues/65818
testWidgets('WidgetSpans with no semantic information are elided from semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
// Without the fix for this bug the pump widget will throw a RangeError.
await tester.pumpWidget(
RichText(
textDirection: TextDirection.ltr,
text: TextSpan(children: <InlineSpan>[
const WidgetSpan(child: SizedBox.shrink()),
TextSpan(
text: 'HELLO',
style: const TextStyle(color: Colors.black),
recognizer: TapGestureRecognizer()..onTap = () {},
)
]),
),
);

expect(semantics, hasSemantics(TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: 1,
rect: const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0),
transform: Matrix4(
3.0,0.0,0.0,0.0,
0.0,3.0,0.0,0.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,1.0,
),
children: <TestSemantics>[
TestSemantics(
rect: const Rect.fromLTRB(-4.0, -4.0, 74.0, 18.0),
id: 2,
label: 'HELLO',
actions: <SemanticsAction>[
SemanticsAction.tap,
],
flags: <SemanticsFlag>[
SemanticsFlag.isLink,
],
),
],
),
],
)));
}, semanticsEnabled: true, skip: isBrowser); // Browser semantics have different sizes.
}

Future<void> _pumpTextWidget({ WidgetTester tester, String text, TextOverflow overflow }) {
Expand Down

0 comments on commit 13fcedc

Please sign in to comment.