Skip to content

Add support for double tap and drag for text selection#109573

Merged
auto-submit[bot] merged 201 commits intoflutter:masterfrom
Renzo-Olivares:tap_drag_gestures
Dec 21, 2022
Merged

Add support for double tap and drag for text selection#109573
auto-submit[bot] merged 201 commits intoflutter:masterfrom
Renzo-Olivares:tap_drag_gestures

Conversation

@Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Aug 15, 2022

This change adds support for double tap + drag, to select word by word when double tapping and then dragging the mouse.

This change also adds a new gesture recognizers that will be specifically useful for text selection:

  • TapAndDragGestureRecognizer

This recognizer makes use of a _TapStatusTrackerMixin to keep track of the tap count.

TextSelectionGestureDetector no longer uses a TapGestureRecognizer or PanGestureRecognizer. TapUp,TapDown, TapCancel, onStart, onUpdate, onEnd, and onCancel are now handled by the new recognizer.

Currently our text selection system does not support double tap + drag (selects word by word) and triple tap + drag (selects line by line). This PR adds support for this behavior by bundling the handling of tap up and tap down with a drag gesture recognizer and long press gesture recognizer. This helps us avoid having to pass state around to accomplish the same behavior. For example, this behavior could also be accomplished by having the TapGestureRecognizer.onTapDown callback, save the tap count, then this tap count can be used by the DragGestureRecognizer.onUpdate callback to determine if the selection should be updated character by character, word by word, or line by line. Some disadvantages of passing state around between gesture recognizers are that you can't accomplish this behavior in a classes initializer (Trying to build a default mapping of gesture recognizers for text selection https://github.com/Renzo-Olivares/flutter/blob/3dbffa3922c656e5c2f97fb6ff8d42b4573d152c/packages/flutter/lib/src/widgets/default_selection_gestures.dart#L24).

Will be handled in separate PR:
Selection area #104552

Fixes #99071, #64550, #23973

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.

Loading
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: cupertino flutter/packages/flutter/cupertino repository f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double click and drag

4 participants