-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Currently the flutter text selection is fairly limited. Historically this is based on the same code that enables text interaction in text edit environments. This has lead to two peculiarities:
-
It is text field specific, instead of being global. This prevents copying of text together that happens to be grouped into different
SelectableTextwidgets. -
It is opt-in. This makes sense for mobile where touch gestures are heavily overloaded, but on desktop and desktop web applications drag gestures universally perform text selection. In general, requiring an opt-in is fairly user hostile.
These two problems can be addressed separately, but together would make text selection behave as a user would expect.
In order to make text selection global, we'd need to hoist the selection logic into a new widget, lets call it a SelectionArea. This could be introduced by default under the WidgetsApp. This widget would introduce the correct drag gesture detector which wrapped the entire screen. It would also provide itself as an inherited widget, allowing text and other widgets types to register their text contents and screen location with. When a drag gesture is performed, it could determine whether the drag "crossed" (from a document perspective) the text selection and highlight it using a single overlay.
Some open questions on this:
- Can we make the screen sized drag gesture detector always lose to more specific gesture detectors? How do we avoid accidentally competing with other contents.
- How do we handle selection through an infinite scrollable / slivers? It seems like screen coordinates would not be sufficient, we'd also need to know some relative coordinates.
- How do we handle non-text data types? Selection could be made generic to support images or other compatible clipboard types.
- How do users opt-out of selection?
Once the selection logic is hoisted into the new widget, the SelectableText widget can be hollowed out a bit. The registration code can be moved into the text RenderObject, with the Text/SelectableText widgets responsible for retrieving the inherited widget. A single field on Text could configure this selection behavior, with it enabled by default on desktop and web and disabled by default elsewhere. SelectableText would be updated to always set this flag to true.
sub task:
- Enable supported devices for TapGestureRecognizer BaseTapGestureRecognizer and TapGestureRecognizer should be able to set supported devices #96556
- Modularize auto scroll logic in Reorderable list Modularize ReorderableListView auto scrolling logic #96562