Unverified Commit b876f78e authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Desktop platforms should not collapse selection on copy (#104209)

* Add tests

* fix tests

* updates
Co-authored-by: 's avatarRenzo Olivares <roliv@google.com>
parent a92f0ef1
...@@ -1693,12 +1693,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1693,12 +1693,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
switch (defaultTargetPlatform) { switch (defaultTargetPlatform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
break;
case TargetPlatform.macOS: case TargetPlatform.macOS:
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
// Collapse the selection and hide the toolbar and handles. // Collapse the selection and hide the toolbar and handles.
userUpdateTextEditingValue( userUpdateTextEditingValue(
TextEditingValue( TextEditingValue(
......
...@@ -248,7 +248,7 @@ void main() { ...@@ -248,7 +248,7 @@ void main() {
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.text, 'blah1 blah2'); expect(controller.text, 'blah1 blah2');
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5)); expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
// Paste it at the end. // Paste it at the end.
......
...@@ -250,7 +250,7 @@ void main() { ...@@ -250,7 +250,7 @@ void main() {
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.text, 'blah1 blah2'); expect(controller.text, 'blah1 blah2');
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5)); expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
// Paste it at the end. // Paste it at the end.
...@@ -359,7 +359,7 @@ void main() { ...@@ -359,7 +359,7 @@ void main() {
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.text, 'blah1 blah2'); expect(controller.text, 'blah1 blah2');
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5)); expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
// Paste it at the end. // Paste it at the end.
......
...@@ -65,7 +65,7 @@ void main() { ...@@ -65,7 +65,7 @@ void main() {
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.text, 'blah1 blah2'); expect(controller.text, 'blah1 blah2');
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5)); expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
// Paste it at the end. // Paste it at the end.
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
await tester.tap(find.text('Copy')); await tester.tap(find.text('Copy'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.text, 'blah1 blah2'); expect(controller.text, 'blah1 blah2');
expect(controller.selection, const TextSelection(baseOffset: 5, extentOffset: 5)); expect(controller.selection, const TextSelection(baseOffset: 0, extentOffset: 5));
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
// Paste it at the end. // Paste it at the end.
......
...@@ -1553,6 +1553,82 @@ void main() { ...@@ -1553,6 +1553,82 @@ void main() {
expect(find.text('Paste'), findsNothing); expect(find.text('Paste'), findsNothing);
}); });
testWidgets('Copy selection does not collapse selection on desktop and iOS', (WidgetTester tester) async {
final TextEditingController localController = TextEditingController(text: 'Hello world');
await tester.pumpWidget(
MaterialApp(
home: EditableText(
backgroundCursorColor: Colors.grey,
controller: localController,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
selectionControls: materialTextSelectionControls,
),
),
);
final EditableTextState state =
tester.state<EditableTextState>(find.byType(EditableText));
// Show the toolbar.
state.renderEditable.selectWordsInRange(
from: Offset.zero,
cause: SelectionChangedCause.tap,
);
await tester.pump();
final TextSelection copySelectionRange = localController.selection;
state.showToolbar();
await tester.pumpAndSettle();
expect(find.text('Copy'), findsOneWidget);
await tester.tap(find.text('Copy'));
await tester.pumpAndSettle();
expect(copySelectionRange, localController.selection);
expect(find.text('Copy'), findsNothing);
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows })); // [intended]
testWidgets('Copy selection collapses selection and hides the toolbar on Android and Fuchsia', (WidgetTester tester) async {
final TextEditingController localController = TextEditingController(text: 'Hello world');
await tester.pumpWidget(
MaterialApp(
home: EditableText(
backgroundCursorColor: Colors.grey,
controller: localController,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
selectionControls: materialTextSelectionControls,
),
),
);
final EditableTextState state =
tester.state<EditableTextState>(find.byType(EditableText));
// Show the toolbar.
state.renderEditable.selectWordsInRange(
from: Offset.zero,
cause: SelectionChangedCause.tap,
);
await tester.pump();
final TextSelection copySelectionRange = localController.selection;
state.showToolbar();
await tester.pumpAndSettle();
expect(find.text('Copy'), findsOneWidget);
await tester.tap(find.text('Copy'));
await tester.pumpAndSettle();
expect(localController.selection, TextSelection.collapsed(offset: copySelectionRange.extentOffset));
expect(find.text('Copy'), findsNothing);
}, skip: kIsWeb, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia })); // [intended]
testWidgets('can show the toolbar after clearing all text', (WidgetTester tester) async { testWidgets('can show the toolbar after clearing all text', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/35998. // Regression test for https://github.com/flutter/flutter/issues/35998.
await tester.pumpWidget( await tester.pumpWidget(
......
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