Skip to content
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

Remove mouse tap text drag selection throttling to improve responsiveness #123460

Merged
merged 6 commits into from Apr 6, 2023

Conversation

loune
Copy link
Contributor

@loune loune commented Mar 25, 2023

Currently, drag selecting text fields with a mouse in Flutter desktop and web feels sluggish, especially compared to platform native applications. This is due to the throttling of text selection updates with the aim of reducing excessive layout. This PR removes the drag selection throttling.

Since there is already logic which stops recalculating layout if the text is unchanged, the throttling on TextSelectionGestureDetector seems unneccesary. Also, text selection via other means such as drag handles on Android and iOS platforms does not have the throttle logic.

Here is a video of text selection before and after the PR:

text-select.mp4

Live Demo: https://flutter-apps-ll-public.s3.us-west-2.amazonaws.com/text-selection/index-frame.html

Related issue: #78908

Since this is removing code, I don't feel unit tests are neccessary but happy to be corrected.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 25, 2023
@gspencergoog
Copy link
Contributor

cc @justinmc

@justinmc
Copy link
Contributor

Thank you for the PR @loune!

@mdebbar I think you originally added text selection throttling when using the mouse, can you comment on this idea to remove it?

It does feel much better to me without the throttling after trying it on web and Linux. I never noticed it was laggy before but now I can't unsee it...

@loune loune marked this pull request as ready for review April 2, 2023 02:03
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM!

I think the throttling was added when web's text layout was too slow. Things have changed since, so we can remove the throttling.

/// See also:
/// * [TextSelectionGestureDetector], which uses this parameter to avoid excessive updates
/// text layouts in text fields.
Duration? dragUpdateThrottleFrequency;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is public API, which makes removing it a breaking change because some apps might be using it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this will need to be deprecated instead. You can start to ignore the value, but it needs to stay in the API for a while.

Check out other examples of deprecation in the code (search for "@deprecated"), and look at https://github.com/flutter/flutter/wiki/Tree-hygiene#deprecations

Be sure to update the documentation comment to make it obvious that the field is deprecated, and that it will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware TapAndDragGestureRecognizer could be used by other apps. If that's the case then perhaps we keep dragUpdateThrottleFrequency and just make the text_selection.dart changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

@loune That sounds good to me. I think you can also remove the comments in tap_and_drag_gestures.dart related to this issue.

/// See also:
///   * [TextSelectionGestureDetector], which uses this parameter to avoid excessive updates
///     text layouts in text fields.

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM but Google testing is failing. I'll try to see what's happening there.

@Renzo-Olivares
Copy link
Contributor

This is passing google testing (ran locally). Will merge once all the github tests are green.

@Renzo-Olivares
Copy link
Contributor

This needs to be synced up to master again due to some recent changes in text_selection.dart .

@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 6, 2023
@auto-submit auto-submit bot merged commit 5eb236c into flutter:master Apr 6, 2023
72 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 6, 2023
@loune loune deleted the remove-text-sel-throttle branch April 6, 2023 20:31
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
…ness (flutter#123460)

Remove mouse tap text drag selection throttling to improve responsiveness
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
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 f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants