Skip to content

Commit 6a88c22

Browse files
authored
SelectableRegion does not merge child semantics nodes (#104659)
1 parent 3e7e01c commit 6a88c22

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

packages/flutter/lib/src/widgets/selectable_region.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
780780
child: Actions(
781781
actions: _actions,
782782
child: Focus(
783+
includeSemantics: false,
783784
focusNode: widget.focusNode,
784785
child: SelectionContainer(
785786
registrar: this,

packages/flutter/test/widgets/selectable_region_test.dart

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
1010
import 'package:flutter_test/flutter_test.dart';
1111

1212
import '../widgets/clipboard_utils.dart';
13+
import 'semantics_tester.dart';
1314

1415
Offset textOffsetToPosition(RenderParagraph paragraph, int offset) {
1516
const Rect caret = Rect.fromLTWH(0.0, 0.0, 2.0, 20.0);
@@ -34,7 +35,7 @@ void main() {
3435
TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, null);
3536
});
3637

37-
group('SelectionArea', () {
38+
group('SelectableRegion', () {
3839
testWidgets('mouse selection sends correct events', (WidgetTester tester) async {
3940
final UniqueKey spy = UniqueKey();
4041
await tester.pumpWidget(
@@ -94,6 +95,81 @@ void main() {
9495
);
9596
});
9697

98+
testWidgets('does not merge semantics node of the children', (WidgetTester tester) async {
99+
final SemanticsTester semantics = SemanticsTester(tester);
100+
await tester.pumpWidget(
101+
MaterialApp(
102+
home: SelectableRegion(
103+
focusNode: FocusNode(),
104+
selectionControls: materialTextSelectionControls,
105+
child: Scaffold(
106+
body: Center(
107+
child: Column(
108+
mainAxisSize: MainAxisSize.min,
109+
children: <Widget>[
110+
const Text('Line one'),
111+
const Text('Line two'),
112+
ElevatedButton(
113+
onPressed: () {},
114+
child: const Text('Button'),
115+
)
116+
],
117+
),
118+
),
119+
),
120+
),
121+
),
122+
);
123+
124+
expect(
125+
semantics,
126+
hasSemantics(
127+
TestSemantics.root(
128+
children: <TestSemantics>[
129+
TestSemantics(
130+
textDirection: TextDirection.ltr,
131+
children: <TestSemantics>[
132+
TestSemantics(
133+
children: <TestSemantics>[
134+
TestSemantics(
135+
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
136+
children: <TestSemantics>[
137+
TestSemantics(
138+
label: 'Line one',
139+
textDirection: TextDirection.ltr,
140+
),
141+
TestSemantics(
142+
label: 'Line two',
143+
textDirection: TextDirection.ltr,
144+
),
145+
TestSemantics(
146+
flags: <SemanticsFlag>[
147+
SemanticsFlag.isButton,
148+
SemanticsFlag.hasEnabledState,
149+
SemanticsFlag.isEnabled,
150+
SemanticsFlag.isFocusable
151+
],
152+
actions: <SemanticsAction>[SemanticsAction.tap],
153+
label: 'Button',
154+
textDirection: TextDirection.ltr,
155+
),
156+
],
157+
),
158+
],
159+
),
160+
],
161+
),
162+
],
163+
),
164+
ignoreRect: true,
165+
ignoreTransform: true,
166+
ignoreId: true,
167+
),
168+
);
169+
170+
semantics.dispose();
171+
});
172+
97173
testWidgets('mouse selection always cancels previous selection', (WidgetTester tester) async {
98174
final UniqueKey spy = UniqueKey();
99175
await tester.pumpWidget(

0 commit comments

Comments
 (0)