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

Hide selection handles from semantics (#76641)

* Hide selection handles from semantics

* update comment
parent 1794e81f
...@@ -547,22 +547,31 @@ class TextSelectionOverlay { ...@@ -547,22 +547,31 @@ class TextSelectionOverlay {
} }
Widget _buildHandle(BuildContext context, _TextSelectionHandlePosition position) { Widget _buildHandle(BuildContext context, _TextSelectionHandlePosition position) {
Widget handle;
if ((_selection.isCollapsed && position == _TextSelectionHandlePosition.end) || if ((_selection.isCollapsed && position == _TextSelectionHandlePosition.end) ||
selectionControls == null) selectionControls == null)
return Container(); // hide the second handle when collapsed handle = Container(); // hide the second handle when collapsed
return Visibility( else {
visible: handlesVisible, handle = Visibility(
child: _TextSelectionHandleOverlay( visible: handlesVisible,
onSelectionHandleChanged: (TextSelection newSelection) { _handleSelectionHandleChanged(newSelection, position); }, child: _TextSelectionHandleOverlay(
onSelectionHandleTapped: onSelectionHandleTapped, onSelectionHandleChanged: (TextSelection newSelection) {
startHandleLayerLink: startHandleLayerLink, _handleSelectionHandleChanged(newSelection, position);
endHandleLayerLink: endHandleLayerLink, },
renderObject: renderObject, onSelectionHandleTapped: onSelectionHandleTapped,
selection: _selection, startHandleLayerLink: startHandleLayerLink,
selectionControls: selectionControls, endHandleLayerLink: endHandleLayerLink,
position: position, renderObject: renderObject,
dragStartBehavior: dragStartBehavior, selection: _selection,
)); selectionControls: selectionControls,
position: position,
dragStartBehavior: dragStartBehavior,
)
);
}
return ExcludeSemantics(
child: handle,
);
} }
Widget _buildToolbar(BuildContext context) { Widget _buildToolbar(BuildContext context) {
......
...@@ -1119,6 +1119,47 @@ void main() { ...@@ -1119,6 +1119,47 @@ void main() {
expect(fadeFinder, findsNothing); expect(fadeFinder, findsNothing);
}); });
testWidgets('selection handles are excluded from the semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final TextEditingController controller = TextEditingController();
await tester.pumpWidget(
overlay(
child: TextField(
controller: controller,
),
),
);
const String testValue = 'abcdefghi';
await tester.enterText(find.byType(TextField), testValue);
expect(controller.value.text, testValue);
await skipPastScrollingAnimation(tester);
// Tap on the text field to show the handle.
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
// The semantics should only have the text field.
expect(semantics, hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
id: 1,
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isFocused],
actions: <SemanticsAction>[SemanticsAction.tap,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.setSelection, SemanticsAction.paste,
SemanticsAction.moveCursorBackwardByWord],
value: 'abcdefghi',
textDirection: TextDirection.ltr,
textSelection: const TextSelection.collapsed(offset: 9),
),
],
),
ignoreRect: true,
ignoreTransform: true,
));
semantics.dispose();
});
testWidgets('Mouse long press is just like a tap', (WidgetTester tester) async { testWidgets('Mouse long press is just like a tap', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(); final TextEditingController controller = TextEditingController();
......
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