-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix TextField selects all content after the application is resumed #156968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TextField selects all content after the application is resumed #156968
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this approach LGTM... It does seem like it should be possible to know the cause of a focus change, but without that functionality, this seems to be the best way to do it. @gspencergoog is this a reliable way to do this or is there a better way?
If Greg is onboard then this just needs a test and a comment somewhere explaining what this is for, maybe on the declaration of justResumed.
I checked out the code locally and confirmed that it works in all the situations it should:
| Scenario | Works? |
|---|---|
| Changing to another window and returning on desktop (Linux) | ✔️ |
| Changing tabs on Chrome | ✔️ |
| Changing to another window and returning to Chrome | ✔️ |
13a94f1 to
8c52729
Compare
gspencergoog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
|
|
||
| expect(focusNode1.hasFocus, true); | ||
| expect(controller1.selection, collapsedAtEnd('Flutter!').selection); | ||
| }, variant: TargetPlatformVariant.all()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Is TargetPlatformVariant.all() necessary? I think the behavior will be the same for all platform variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I think it is important to keep it, otherwise this test will not fail if the fix is removed (the 'select all' behavior is only desktop and web so the logic I added to fix this issue is not used on Android).
|
Reason for revert: Google3 roll failing - see b/375019489 |
…esumed (#156968)" (#157378) Reverts: #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](#156078). ## Tests Adds 1 test.
|
I'm sorry for the revert here! So what happened is some Google integration tests failed at this line:
The test logic is doing something like: I imagine the test logic needs updating, but I'm not sure exactly what to do yet, hence the revert. Should I try to fix this by simulating a change to the 'hidden' state before 'paused' ? |
|
@jacobsimionato See this diagram for the allowed state transitions (or this one) I think the test is doing an invalid state transition, and one that the engine wouldn't send. The engine implementations are coded to synthesize any intermediate state transitions if the platform jumps from one state to another so that the state machine is followed, and an application can count on getting all the states in the expected order. So, yes, you should probably add that transition, but if the test is expected to start in a particular state, then you should generate any intermediate states too, so if, for instance, the test starts at tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused); |
|
I've now updated the internal tests to do the valid state transitions as you suggested. @bleroux could you reland the PR? Sorry to make you do it twice! |
Hey @jacobsimionato 👋 ! Here is the reland: #157399. |
…sumed" (#157399) ## Description Relands #156968 wich was reverted in #157378 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](#156078). ## Tests Adds 1 test.
…esumed (flutter#156968)" (flutter#157378) Reverts: 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](flutter#156078). ## Tests Adds 1 test.
…sumed" (flutter#157399) ## Description Relands flutter#156968 wich was reverted in flutter#157378 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](flutter#156078). ## Tests Adds 1 test.

Description
This PR makes
EditableTextaware 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
TextFieldwas selected whenever aTextFieldgained focus. This is the correct behavior when tabbing between fields but it is not when a field regains focus after the application is resumedRelated Issue
Fixes When switching to another browser tab or window and then going back, all text on TextField is selected automatically.
Tests
Adds 1 test.