Skip to content

Commit 6b2b2aa

Browse files
committed
Add comment
1 parent b2fb04e commit 6b2b2aa

File tree

2 files changed

+173
-4
lines changed

2 files changed

+173
-4
lines changed

lib/src/widgets/delegate.dart

Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,94 @@ abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
1818
bool getSelectionEnabled();
1919
}
2020

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].
2139
class EditorTextSelectionGestureDetectorBuilder {
22-
EditorTextSelectionGestureDetectorBuilder(this.delegate);
40+
/// Creates a [EditorTextSelectionGestureDetectorBuilder].
41+
///
42+
/// The [delegate] must not be null.
43+
EditorTextSelectionGestureDetectorBuilder({required this.delegate});
2344

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
2451
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.
2558
bool shouldShowSelectionToolbar = true;
2659

60+
/// The [State] of the [EditableText] for which the builder will provide a
61+
/// [EditorTextSelectionGestureDetector].
62+
@protected
2763
EditorState? getEditor() {
2864
return delegate.getEditableTextKey().currentState;
2965
}
3066

67+
/// The [RenderObject] of the [EditableText] for which the builder will
68+
/// provide a [EditorTextSelectionGestureDetector].
69+
@protected
3170
RenderEditor? getRenderEditor() {
3271
return getEditor()!.getRenderEditor();
3372
}
3473

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
3585
void onTapDown(TapDownDetails details) {
3686
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.
3891
final kind = details.kind;
3992
shouldShowSelectionToolbar = kind == null ||
4093
kind == PointerDeviceKind.touch ||
4194
kind == PointerDeviceKind.stylus;
4295
}
4396

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
44109
void onForcePressStart(ForcePressDetails details) {
45110
assert(delegate.getForcePressEnabled());
46111
shouldShowSelectionToolbar = true;
@@ -53,6 +118,18 @@ class EditorTextSelectionGestureDetectorBuilder {
53118
}
54119
}
55120

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
56133
void onForcePressEnd(ForcePressDetails details) {
57134
assert(delegate.getForcePressEnabled());
58135
getRenderEditor()!.selectWordsInRange(
@@ -65,14 +142,44 @@ class EditorTextSelectionGestureDetectorBuilder {
65142
}
66143
}
67144

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
68154
void onSingleTapUp(TapUpDetails details) {
69155
if (delegate.getSelectionEnabled()) {
70156
getRenderEditor()!.selectWordEdge(SelectionChangedCause.tap);
71157
}
72158
}
73159

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+
}
75172

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
76183
void onSingleLongTapStart(LongPressStartDetails details) {
77184
if (delegate.getSelectionEnabled()) {
78185
getRenderEditor()!.selectPositionAt(
@@ -82,6 +189,16 @@ class EditorTextSelectionGestureDetectorBuilder {
82189
}
83190
}
84191

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
85202
void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
86203
if (delegate.getSelectionEnabled()) {
87204
getRenderEditor()!.selectPositionAt(
@@ -91,12 +208,31 @@ class EditorTextSelectionGestureDetectorBuilder {
91208
}
92209
}
93210

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
94220
void onSingleLongTapEnd(LongPressEndDetails details) {
95221
if (shouldShowSelectionToolbar) {
96222
getEditor()!.showToolbar();
97223
}
98224
}
99225

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
100236
void onDoubleTapDown(TapDownDetails details) {
101237
if (delegate.getSelectionEnabled()) {
102238
getRenderEditor()!.selectWord(SelectionChangedCause.tap);
@@ -106,20 +242,52 @@ class EditorTextSelectionGestureDetectorBuilder {
106242
}
107243
}
108244

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
109254
void onDragSelectionStart(DragStartDetails details) {
110255
getRenderEditor()!.handleDragStart(details);
111256
}
112257

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
113268
void onDragSelectionUpdate(
114269
DragStartDetails startDetails, DragUpdateDetails updateDetails) {
115270
getRenderEditor()!.extendSelection(updateDetails.globalPosition,
116271
cause: SelectionChangedCause.drag);
117272
}
118273

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
119283
void onDragSelectionEnd(DragEndDetails details) {
120284
getRenderEditor()!.handleDragEnd(details);
121285
}
122286

287+
/// Returns a [EditorTextSelectionGestureDetector] configured with
288+
/// the handlers provided by this builder.
289+
///
290+
/// The [child] or its subtree should contain [EditableText].
123291
Widget build(HitTestBehavior behavior, Widget child) {
124292
return EditorTextSelectionGestureDetector(
125293
onTapDown: onTapDown,

lib/src/widgets/editor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ class _QuillEditorState extends State<QuillEditor>
463463

464464
class _QuillEditorSelectionGestureDetectorBuilder
465465
extends EditorTextSelectionGestureDetectorBuilder {
466-
_QuillEditorSelectionGestureDetectorBuilder(this._state) : super(_state);
466+
_QuillEditorSelectionGestureDetectorBuilder(this._state)
467+
: super(delegate: _state);
467468

468469
final _QuillEditorState _state;
469470

0 commit comments

Comments
 (0)