Reverts "Fix TextField selects all content after the application is resumed (#156968)" (#157378)

Reverts: flutter/flutter#156968
Initiated by: jacobsimionato
Reason for reverting: Google3 roll failing - see b/375019489
Original PR Author: bleroux

Reviewed By: {justinmc, gspencergoog}

This change reverts the following previous change:
## Description

This PR makes `EditableText` aware of the lifecycle 'resumed' state to let the current selection unchanged when the application is resumed (on web and desktop, 'resumed' means the Flutter app window regained focus).

Before this PR, on web and desktop, the whole content of a `TextField` was selected whenever a `TextField` gained focus. This is the correct behavior when tabbing between fields but it is not when a field regains focus after the application is resumed 

## Related Issue

Fixes [When switching to another browser tab or window and then going back, all text on TextField is selected automatically](https://github.com/flutter/flutter/issues/156078).

## Tests

Adds 1 test.
This commit is contained in:
auto-submit[bot]
2024-10-22 19:59:22 +00:00
committed by GitHub
parent 48149781f2
commit 60d4c9b741
2 changed files with 1 additions and 50 deletions

View File

@@ -26,7 +26,6 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'actions.dart';
import 'app_lifecycle_listener.dart';
import 'autofill.dart';
import 'automatic_keep_alive.dart';
import 'basic.dart';
@@ -2363,9 +2362,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
Orientation? _lastOrientation;
late final AppLifecycleListener _appLifecycleListener;
bool _justResumed = false;
@override
bool get wantKeepAlive => widget.focusNode.hasFocus;
@@ -2988,9 +2984,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
widget.focusNode.addListener(_handleFocusChanged);
_cursorVisibilityNotifier.value = widget.showCursor;
_spellCheckConfiguration = _inferSpellCheckConfiguration(widget.spellCheckConfiguration);
_appLifecycleListener = AppLifecycleListener(
onResume: () => _justResumed = true,
);
_initProcessTextActions();
}
@@ -3205,7 +3198,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
clipboardStatus.removeListener(_onChangedClipboardStatus);
clipboardStatus.dispose();
_cursorVisibilityNotifier.dispose();
_appLifecycleListener.dispose();
FocusManager.instance.removeListener(_unflagInternalFocus);
_disposeScrollNotificationObserver();
super.dispose();
@@ -4408,9 +4400,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
final bool shouldSelectAll = widget.selectionEnabled
&& (kIsWeb || isDesktop)
&& !_isMultiline
&& !_nextFocusChangeIsInternal
&& !_justResumed;
_justResumed = false;
&& !_nextFocusChangeIsInternal;
if (shouldSelectAll) {
// On native web and desktop platforms, single line <input> tags
// select all when receiving focus.

View File

@@ -17017,45 +17017,6 @@ void main() {
},
skip: !kIsWeb, // [intended]
);
// Regression test for https://github.com/flutter/flutter/issues/156078.
testWidgets('when having focus regained after the app resumed', (WidgetTester tester) async {
Future<void> setAppLifeCycleState(AppLifecycleState state) async {
final ByteData? message = const StringCodec().encodeMessage(state.toString());
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage('flutter/lifecycle', message, (_) {});
}
final TextEditingController controller1 = TextEditingController(text: 'Flutter!');
addTearDown(controller1.dispose);
final FocusNode focusNode1 = FocusNode();
addTearDown(focusNode1.dispose);
await tester.pumpWidget(
MaterialApp(
home: Center(
child: EditableText(
key: ValueKey<String>(controller1.text),
controller: controller1,
focusNode: focusNode1,
autofocus: true,
style: Typography.material2018().black.titleMedium!,
cursorColor: Colors.blue,
backgroundCursorColor: Colors.grey,
),
),
),
);
expect(focusNode1.hasFocus, true);
expect(controller1.selection, collapsedAtEnd('Flutter!').selection);
await setAppLifeCycleState(AppLifecycleState.inactive);
await setAppLifeCycleState(AppLifecycleState.resumed);
expect(focusNode1.hasFocus, true);
expect(controller1.selection, collapsedAtEnd('Flutter!').selection);
}, variant: TargetPlatformVariant.all());
});
testWidgets('EditableText respects MediaQuery.boldText', (WidgetTester tester) async {