Skip to content

Commit

Permalink
SelectableRegion does not merge child semantics nodes (#104659)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored May 26, 2022
1 parent 3e7e01c commit 6a88c22
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/flutter/lib/src/widgets/selectable_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
child: Actions(
actions: _actions,
child: Focus(
includeSemantics: false,
focusNode: widget.focusNode,
child: SelectionContainer(
registrar: this,
Expand Down
78 changes: 77 additions & 1 deletion packages/flutter/test/widgets/selectable_region_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

import '../widgets/clipboard_utils.dart';
import 'semantics_tester.dart';

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

group('SelectionArea', () {
group('SelectableRegion', () {
testWidgets('mouse selection sends correct events', (WidgetTester tester) async {
final UniqueKey spy = UniqueKey();
await tester.pumpWidget(
Expand Down Expand Up @@ -94,6 +95,81 @@ void main() {
);
});

testWidgets('does not merge semantics node of the children', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
MaterialApp(
home: SelectableRegion(
focusNode: FocusNode(),
selectionControls: materialTextSelectionControls,
child: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Line one'),
const Text('Line two'),
ElevatedButton(
onPressed: () {},
child: const Text('Button'),
)
],
),
),
),
),
),
);

expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
label: 'Line one',
textDirection: TextDirection.ltr,
),
TestSemantics(
label: 'Line two',
textDirection: TextDirection.ltr,
),
TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocusable
],
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'Button',
textDirection: TextDirection.ltr,
),
],
),
],
),
],
),
],
),
ignoreRect: true,
ignoreTransform: true,
ignoreId: true,
),
);

semantics.dispose();
});

testWidgets('mouse selection always cancels previous selection', (WidgetTester tester) async {
final UniqueKey spy = UniqueKey();
await tester.pumpWidget(
Expand Down

0 comments on commit 6a88c22

Please sign in to comment.