@@ -18,29 +18,94 @@ abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
18
18
bool getSelectionEnabled ();
19
19
}
20
20
21
+ /// Builds a [EditorTextSelectionGestureDetector] to wrap an [EditableText] .
22
+ ///
23
+ /// The class implements sensible defaults for many user interactions
24
+ /// with an [EditableText] (see the documentation of the various gesture handler
25
+ /// methods, e.g. [onTapDown] , [onForcePressStart] , etc.). Subclasses of
26
+ /// [EditorTextSelectionGestureDetectorBuilder] can change the behavior
27
+ /// performed in responds to these gesture events by overriding
28
+ /// the corresponding handler methods of this class.
29
+ ///
30
+ /// The resulting [EditorTextSelectionGestureDetector] to wrap an [EditableText]
31
+ /// is obtained by calling [buildGestureDetector] .
32
+ ///
33
+ /// See also:
34
+ ///
35
+ /// * [TextField] , which uses a subclass to implement the Material-specific
36
+ /// gesture logic of an [EditableText].
37
+ /// * [CupertinoTextField] , which uses a subclass to implement the
38
+ /// Cupertino-specific gesture logic of an [EditableText].
21
39
class EditorTextSelectionGestureDetectorBuilder {
22
- EditorTextSelectionGestureDetectorBuilder (this .delegate);
40
+ /// Creates a [EditorTextSelectionGestureDetectorBuilder] .
41
+ ///
42
+ /// The [delegate] must not be null.
43
+ EditorTextSelectionGestureDetectorBuilder ({required this .delegate});
23
44
45
+ /// The delegate for this [EditorTextSelectionGestureDetectorBuilder] .
46
+ ///
47
+ /// The delegate provides the builder with information about what actions can
48
+ /// currently be performed on the textfield. Based on this, the builder adds
49
+ /// the correct gesture handlers to the gesture detector.
50
+ @protected
24
51
final EditorTextSelectionGestureDetectorBuilderDelegate delegate;
52
+
53
+ /// Whether to show the selection toolbar.
54
+ ///
55
+ /// It is based on the signal source when a [onTapDown] is called. This getter
56
+ /// will return true if current [onTapDown] event is triggered by a touch or
57
+ /// a stylus.
25
58
bool shouldShowSelectionToolbar = true ;
26
59
60
+ /// The [State] of the [EditableText] for which the builder will provide a
61
+ /// [EditorTextSelectionGestureDetector] .
62
+ @protected
27
63
EditorState ? getEditor () {
28
64
return delegate.getEditableTextKey ().currentState;
29
65
}
30
66
67
+ /// The [RenderObject] of the [EditableText] for which the builder will
68
+ /// provide a [EditorTextSelectionGestureDetector] .
69
+ @protected
31
70
RenderEditor ? getRenderEditor () {
32
71
return getEditor ()! .getRenderEditor ();
33
72
}
34
73
74
+ /// Handler for [EditorTextSelectionGestureDetector.onTapDown] .
75
+ ///
76
+ /// By default, it forwards the tap to [RenderEditable.handleTapDown] and sets
77
+ /// [shouldShowSelectionToolbar] to true if the tap was initiated by a finger
78
+ /// or stylus.
79
+ ///
80
+ /// See also:
81
+ ///
82
+ /// * [EditorTextSelectionGestureDetector.onTapDown] ,
83
+ /// which triggers this callback.
84
+ @protected
35
85
void onTapDown (TapDownDetails details) {
36
86
getRenderEditor ()! .handleTapDown (details);
37
-
87
+ // The selection overlay should only be shown when the user is interacting
88
+ // through a touch screen (via either a finger or a stylus).
89
+ // A mouse shouldn't trigger the selection overlay.
90
+ // For backwards-compatibility, we treat a null kind the same as touch.
38
91
final kind = details.kind;
39
92
shouldShowSelectionToolbar = kind == null ||
40
93
kind == PointerDeviceKind .touch ||
41
94
kind == PointerDeviceKind .stylus;
42
95
}
43
96
97
+ /// Handler for [EditorTextSelectionGestureDetector.onForcePressStart] .
98
+ ///
99
+ /// By default, it selects the word at the position of the force press,
100
+ /// if selection is enabled.
101
+ ///
102
+ /// This callback is only applicable when force press is enabled.
103
+ ///
104
+ /// See also:
105
+ ///
106
+ /// * [EditorTextSelectionGestureDetector.onForcePressStart] ,
107
+ /// which triggers this callback.
108
+ @protected
44
109
void onForcePressStart (ForcePressDetails details) {
45
110
assert (delegate.getForcePressEnabled ());
46
111
shouldShowSelectionToolbar = true ;
@@ -53,6 +118,18 @@ class EditorTextSelectionGestureDetectorBuilder {
53
118
}
54
119
}
55
120
121
+ /// Handler for [EditorTextSelectionGestureDetector.onForcePressEnd] .
122
+ ///
123
+ /// By default, it selects words in the range specified in [details] and shows
124
+ /// toolbar if it is necessary.
125
+ ///
126
+ /// This callback is only applicable when force press is enabled.
127
+ ///
128
+ /// See also:
129
+ ///
130
+ /// * [EditorTextSelectionGestureDetector.onForcePressEnd] ,
131
+ /// which triggers this callback.
132
+ @protected
56
133
void onForcePressEnd (ForcePressDetails details) {
57
134
assert (delegate.getForcePressEnabled ());
58
135
getRenderEditor ()! .selectWordsInRange (
@@ -65,14 +142,44 @@ class EditorTextSelectionGestureDetectorBuilder {
65
142
}
66
143
}
67
144
145
+ /// Handler for [EditorTextSelectionGestureDetector.onSingleTapUp] .
146
+ ///
147
+ /// By default, it selects word edge if selection is enabled.
148
+ ///
149
+ /// See also:
150
+ ///
151
+ /// * [EditorTextSelectionGestureDetector.onSingleTapUp] , which triggers
152
+ /// this callback.
153
+ @protected
68
154
void onSingleTapUp (TapUpDetails details) {
69
155
if (delegate.getSelectionEnabled ()) {
70
156
getRenderEditor ()! .selectWordEdge (SelectionChangedCause .tap);
71
157
}
72
158
}
73
159
74
- void onSingleTapCancel () {}
160
+ /// Handler for [EditorTextSelectionGestureDetector.onSingleTapCancel] .
161
+ ///
162
+ /// By default, it services as place holder to enable subclass override.
163
+ ///
164
+ /// See also:
165
+ ///
166
+ /// * [EditorTextSelectionGestureDetector.onSingleTapCancel] , which triggers
167
+ /// this callback.
168
+ @protected
169
+ void onSingleTapCancel () {
170
+ /* Subclass should override this method if needed. */
171
+ }
75
172
173
+ /// Handler for [EditorTextSelectionGestureDetector.onSingleLongTapStart] .
174
+ ///
175
+ /// By default, it selects text position specified in [details] if selection
176
+ /// is enabled.
177
+ ///
178
+ /// See also:
179
+ ///
180
+ /// * [EditorTextSelectionGestureDetector.onSingleLongTapStart] ,
181
+ /// which triggers this callback.
182
+ @protected
76
183
void onSingleLongTapStart (LongPressStartDetails details) {
77
184
if (delegate.getSelectionEnabled ()) {
78
185
getRenderEditor ()! .selectPositionAt (
@@ -82,6 +189,16 @@ class EditorTextSelectionGestureDetectorBuilder {
82
189
}
83
190
}
84
191
192
+ /// Handler for [EditorTextSelectionGestureDetector.onSingleLongTapMoveUpdate]
193
+ ///
194
+ /// By default, it updates the selection location specified in [details] if
195
+ /// selection is enabled.
196
+ ///
197
+ /// See also:
198
+ ///
199
+ /// * [EditorTextSelectionGestureDetector.onSingleLongTapMoveUpdate] , which
200
+ /// triggers this callback.
201
+ @protected
85
202
void onSingleLongTapMoveUpdate (LongPressMoveUpdateDetails details) {
86
203
if (delegate.getSelectionEnabled ()) {
87
204
getRenderEditor ()! .selectPositionAt (
@@ -91,12 +208,31 @@ class EditorTextSelectionGestureDetectorBuilder {
91
208
}
92
209
}
93
210
211
+ /// Handler for [EditorTextSelectionGestureDetector.onSingleLongTapEnd] .
212
+ ///
213
+ /// By default, it shows toolbar if necessary.
214
+ ///
215
+ /// See also:
216
+ ///
217
+ /// * [EditorTextSelectionGestureDetector.onSingleLongTapEnd] ,
218
+ /// which triggers this callback.
219
+ @protected
94
220
void onSingleLongTapEnd (LongPressEndDetails details) {
95
221
if (shouldShowSelectionToolbar) {
96
222
getEditor ()! .showToolbar ();
97
223
}
98
224
}
99
225
226
+ /// Handler for [EditorTextSelectionGestureDetector.onDoubleTapDown] .
227
+ ///
228
+ /// By default, it selects a word through [RenderEditable.selectWord] if
229
+ /// selectionEnabled and shows toolbar if necessary.
230
+ ///
231
+ /// See also:
232
+ ///
233
+ /// * [EditorTextSelectionGestureDetector.onDoubleTapDown] ,
234
+ /// which triggers this callback.
235
+ @protected
100
236
void onDoubleTapDown (TapDownDetails details) {
101
237
if (delegate.getSelectionEnabled ()) {
102
238
getRenderEditor ()! .selectWord (SelectionChangedCause .tap);
@@ -106,20 +242,52 @@ class EditorTextSelectionGestureDetectorBuilder {
106
242
}
107
243
}
108
244
245
+ /// Handler for [EditorTextSelectionGestureDetector.onDragSelectionStart] .
246
+ ///
247
+ /// By default, it selects a text position specified in [details] .
248
+ ///
249
+ /// See also:
250
+ ///
251
+ /// * [EditorTextSelectionGestureDetector.onDragSelectionStart] ,
252
+ /// which triggers this callback.
253
+ @protected
109
254
void onDragSelectionStart (DragStartDetails details) {
110
255
getRenderEditor ()! .handleDragStart (details);
111
256
}
112
257
258
+ /// Handler for [EditorTextSelectionGestureDetector.onDragSelectionUpdate] .
259
+ ///
260
+ /// By default, it updates the selection location specified in the provided
261
+ /// details objects.
262
+ ///
263
+ /// See also:
264
+ ///
265
+ /// * [EditorTextSelectionGestureDetector.onDragSelectionUpdate] ,
266
+ /// which triggers this callback./lib/src/material/text_field.dart
267
+ @protected
113
268
void onDragSelectionUpdate (
114
269
DragStartDetails startDetails, DragUpdateDetails updateDetails) {
115
270
getRenderEditor ()! .extendSelection (updateDetails.globalPosition,
116
271
cause: SelectionChangedCause .drag);
117
272
}
118
273
274
+ /// Handler for [EditorTextSelectionGestureDetector.onDragSelectionEnd] .
275
+ ///
276
+ /// By default, it services as place holder to enable subclass override.
277
+ ///
278
+ /// See also:
279
+ ///
280
+ /// * [EditorTextSelectionGestureDetector.onDragSelectionEnd] ,
281
+ /// which triggers this callback.
282
+ @protected
119
283
void onDragSelectionEnd (DragEndDetails details) {
120
284
getRenderEditor ()! .handleDragEnd (details);
121
285
}
122
286
287
+ /// Returns a [EditorTextSelectionGestureDetector] configured with
288
+ /// the handlers provided by this builder.
289
+ ///
290
+ /// The [child] or its subtree should contain [EditableText] .
123
291
Widget build (HitTestBehavior behavior, Widget child) {
124
292
return EditorTextSelectionGestureDetector (
125
293
onTapDown: onTapDown,
0 commit comments