Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Oct 23, 2024

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.

Tests

Adds 1 test.

@bleroux bleroux changed the title Reland "Fix TextField selects all content after the application is resumed Reland "Fix TextField selects all content after the application is resumed" Oct 23, 2024
@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Oct 23, 2024
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 23, 2024
@auto-submit auto-submit bot merged commit b9c889d into flutter:master Oct 23, 2024
@bleroux bleroux deleted the reland_fix_textfield_select_all_after_application_is_resumed branch October 23, 2024 16:36
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
…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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Copy link

@KaushikGupta007 KaushikGupta007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_justResumed flag being stored per EditableTextState, which was set to true on app resume for every TextField, but only reset when each individual field was focused again. This led to unreliable behavior where TextInputAction.next, tab, or programmatic focus would not auto-select text as expected on Web and Desktop after resume.

github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2025
## Description

This PR tweaks the selection logic added in
#157399.
Before this PR (and since
#157399) when the app resumed
while a TextField was selected the selection of the TextField is
maintained. This is the right behavior for the currently focused
TextField. But when there are several TextFields, after the app resumed
and the user move the focus to a another TextField, the behavior should
be to select all the content of the newly focused TextField. To achieve
this the `_justResumed`flag added in
#157399 should be reset as soon
as the focus move as it is needed only for the current focused TextField
to restore its selection just after the app resumed.

## Related Issue

Fixes [Pressing tab does select all content when app is resumed for
TextFields which were not
focused](#177650)

## Tests

- Adds 1 test
walley892 pushed a commit to walley892/flutter that referenced this pull request Oct 30, 2025
## Description

This PR tweaks the selection logic added in
flutter#157399.
Before this PR (and since
flutter#157399) when the app resumed
while a TextField was selected the selection of the TextField is
maintained. This is the right behavior for the currently focused
TextField. But when there are several TextFields, after the app resumed
and the user move the focus to a another TextField, the behavior should
be to select all the content of the newly focused TextField. To achieve
this the `_justResumed`flag added in
flutter#157399 should be reset as soon
as the focus move as it is needed only for the current focused TextField
to restore its selection just after the app resumed.

## Related Issue

Fixes [Pressing tab does select all content when app is resumed for
TextFields which were not
focused](flutter#177650)

## Tests

- Adds 1 test
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
## Description

This PR tweaks the selection logic added in
flutter#157399.
Before this PR (and since
flutter#157399) when the app resumed
while a TextField was selected the selection of the TextField is
maintained. This is the right behavior for the currently focused
TextField. But when there are several TextFields, after the app resumed
and the user move the focus to a another TextField, the behavior should
be to select all the content of the newly focused TextField. To achieve
this the `_justResumed`flag added in
flutter#157399 should be reset as soon
as the focus move as it is needed only for the current focused TextField
to restore its selection just after the app resumed.

## Related Issue

Fixes [Pressing tab does select all content when app is resumed for
TextFields which were not
focused](flutter#177650)

## Tests

- Adds 1 test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TextField] When switching to another browser tab or window and then going back, all text on TextField is selected automatically

3 participants