Skip to content

Commit 1505fce

Browse files
committed
Update EditorTextSelectionGestureDetectorBuilderDelegate
1 parent 8bd15fe commit 1505fce

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

lib/src/widgets/delegate.dart

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,32 @@ typedef EmbedBuilder = Widget Function(
1010

1111
typedef CustomStyleBuilder = TextStyle Function(Attribute attribute);
1212

13+
/// Delegate interface for the [EditorTextSelectionGestureDetectorBuilder].
14+
///
15+
/// The interface is usually implemented by textfield implementations wrapping
16+
/// [EditableText], that use a [EditorTextSelectionGestureDetectorBuilder]
17+
/// to build a [EditorTextSelectionGestureDetector] for their [EditableText].
18+
/// The delegate provides the builder with information about the current state
19+
/// of the textfield.
20+
/// Based on these information, the builder adds the correct gesture handlers
21+
/// to the gesture detector.
22+
///
23+
/// See also:
24+
///
25+
/// * [TextField], which implements this delegate for the Material textfield.
26+
/// * [CupertinoTextField], which implements this delegate for the Cupertino
27+
/// textfield.
1328
abstract class EditorTextSelectionGestureDetectorBuilderDelegate {
14-
GlobalKey<EditorState> getEditableTextKey();
29+
/// [GlobalKey] to the [EditableText] for which the
30+
/// [EditorTextSelectionGestureDetectorBuilder] will build
31+
/// a [EditorTextSelectionGestureDetector].
32+
GlobalKey<EditorState> get editableTextKey;
1533

16-
bool getForcePressEnabled();
34+
/// Whether the textfield should respond to force presses.
35+
bool get forcePressEnabled;
1736

18-
bool getSelectionEnabled();
37+
/// Whether the user may select text in the textfield.
38+
bool get selectionEnabled;
1939
}
2040

2141
/// Builds a [EditorTextSelectionGestureDetector] to wrap an [EditableText].
@@ -60,7 +80,7 @@ class EditorTextSelectionGestureDetectorBuilder {
6080
/// The [State] of the [EditableText] for which the builder will provide a
6181
/// [EditorTextSelectionGestureDetector].
6282
@protected
63-
EditorState? get editor => delegate.getEditableTextKey().currentState;
83+
EditorState? get editor => delegate.editableTextKey.currentState;
6484

6585
/// The [RenderObject] of the [EditableText] for which the builder will
6686
/// provide a [EditorTextSelectionGestureDetector].
@@ -103,9 +123,9 @@ class EditorTextSelectionGestureDetectorBuilder {
103123
/// which triggers this callback.
104124
@protected
105125
void onForcePressStart(ForcePressDetails details) {
106-
assert(delegate.getForcePressEnabled());
126+
assert(delegate.forcePressEnabled);
107127
shouldShowSelectionToolbar = true;
108-
if (delegate.getSelectionEnabled()) {
128+
if (delegate.selectionEnabled) {
109129
renderEditor!.selectWordsInRange(
110130
details.globalPosition,
111131
null,
@@ -127,7 +147,7 @@ class EditorTextSelectionGestureDetectorBuilder {
127147
/// which triggers this callback.
128148
@protected
129149
void onForcePressEnd(ForcePressDetails details) {
130-
assert(delegate.getForcePressEnabled());
150+
assert(delegate.forcePressEnabled);
131151
renderEditor!.selectWordsInRange(
132152
details.globalPosition,
133153
null,
@@ -148,7 +168,7 @@ class EditorTextSelectionGestureDetectorBuilder {
148168
/// this callback.
149169
@protected
150170
void onSingleTapUp(TapUpDetails details) {
151-
if (delegate.getSelectionEnabled()) {
171+
if (delegate.selectionEnabled) {
152172
renderEditor!.selectWordEdge(SelectionChangedCause.tap);
153173
}
154174
}
@@ -177,7 +197,7 @@ class EditorTextSelectionGestureDetectorBuilder {
177197
/// which triggers this callback.
178198
@protected
179199
void onSingleLongTapStart(LongPressStartDetails details) {
180-
if (delegate.getSelectionEnabled()) {
200+
if (delegate.selectionEnabled) {
181201
renderEditor!.selectPositionAt(
182202
from: details.globalPosition,
183203
cause: SelectionChangedCause.longPress,
@@ -196,7 +216,7 @@ class EditorTextSelectionGestureDetectorBuilder {
196216
/// triggers this callback.
197217
@protected
198218
void onSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) {
199-
if (delegate.getSelectionEnabled()) {
219+
if (delegate.selectionEnabled) {
200220
renderEditor!.selectPositionAt(
201221
from: details.globalPosition,
202222
cause: SelectionChangedCause.longPress,
@@ -230,7 +250,7 @@ class EditorTextSelectionGestureDetectorBuilder {
230250
/// which triggers this callback.
231251
@protected
232252
void onDoubleTapDown(TapDownDetails details) {
233-
if (delegate.getSelectionEnabled()) {
253+
if (delegate.selectionEnabled) {
234254
renderEditor!.selectWord(SelectionChangedCause.tap);
235255
if (shouldShowSelectionToolbar) {
236256
editor!.showToolbar();
@@ -289,9 +309,8 @@ class EditorTextSelectionGestureDetectorBuilder {
289309
return EditorTextSelectionGestureDetector(
290310
key: key,
291311
onTapDown: onTapDown,
292-
onForcePressStart:
293-
delegate.getForcePressEnabled() ? onForcePressStart : null,
294-
onForcePressEnd: delegate.getForcePressEnabled() ? onForcePressEnd : null,
312+
onForcePressStart: delegate.forcePressEnabled ? onForcePressStart : null,
313+
onForcePressEnd: delegate.forcePressEnabled ? onForcePressEnd : null,
295314
onSingleTapUp: onSingleTapUp,
296315
onSingleTapCancel: onSingleTapCancel,
297316
onSingleLongTapStart: onSingleLongTapStart,

lib/src/widgets/editor.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,13 @@ class _QuillEditorState extends State<QuillEditor>
569569
}
570570

571571
@override
572-
GlobalKey<EditorState> getEditableTextKey() {
573-
return _editorKey;
574-
}
572+
GlobalKey<EditorState> get editableTextKey => _editorKey;
575573

576574
@override
577-
bool getForcePressEnabled() {
578-
return false;
579-
}
575+
bool get forcePressEnabled => false;
580576

581577
@override
582-
bool getSelectionEnabled() {
583-
return widget.enableInteractiveSelection;
584-
}
578+
bool get selectionEnabled => widget.enableInteractiveSelection;
585579

586580
void _requestKeyboard() {
587581
_editorKey.currentState!.requestKeyboard();
@@ -598,7 +592,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
598592
@override
599593
void onForcePressStart(ForcePressDetails details) {
600594
super.onForcePressStart(details);
601-
if (delegate.getSelectionEnabled() && shouldShowSelectionToolbar) {
595+
if (delegate.selectionEnabled && shouldShowSelectionToolbar) {
602596
editor!.showToolbar();
603597
}
604598
}
@@ -615,7 +609,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
615609
return;
616610
}
617611
}
618-
if (!delegate.getSelectionEnabled()) {
612+
if (!delegate.selectionEnabled) {
619613
return;
620614
}
621615
switch (Theme.of(_state.context).platform) {
@@ -692,7 +686,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
692686

693687
final positionSelected = _isPositionSelected(details);
694688

695-
if (delegate.getSelectionEnabled() && !positionSelected) {
689+
if (delegate.selectionEnabled && !positionSelected) {
696690
switch (Theme.of(_state.context).platform) {
697691
case TargetPlatform.iOS:
698692
case TargetPlatform.macOS:
@@ -754,7 +748,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
754748
}
755749
}
756750

757-
if (delegate.getSelectionEnabled()) {
751+
if (delegate.selectionEnabled) {
758752
switch (Theme.of(_state.context).platform) {
759753
case TargetPlatform.iOS:
760754
case TargetPlatform.macOS:
@@ -785,7 +779,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
785779
return;
786780
}
787781

788-
if (delegate.getSelectionEnabled()) {
782+
if (delegate.selectionEnabled) {
789783
renderEditor!.onSelectionCompleted();
790784
}
791785
}

0 commit comments

Comments
 (0)