Added a property to control the detect word boundary behaviour (#1102)

pull/1103/head
sourabhguptazeil 2 years ago committed by GitHub
parent fdbebef79b
commit c68c2bd030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      lib/src/widgets/delegate.dart
  2. 23
      lib/src/widgets/editor.dart
  3. 3
      lib/src/widgets/text_selection.dart

@ -66,7 +66,9 @@ class EditorTextSelectionGestureDetectorBuilder {
/// Creates a [EditorTextSelectionGestureDetectorBuilder].
///
/// The [delegate] must not be null.
EditorTextSelectionGestureDetectorBuilder({required this.delegate});
EditorTextSelectionGestureDetectorBuilder({
required this.delegate,
this.detectWordBoundary = true});
/// The delegate for this [EditorTextSelectionGestureDetectorBuilder].
///
@ -83,6 +85,8 @@ class EditorTextSelectionGestureDetectorBuilder {
/// a stylus.
bool shouldShowSelectionToolbar = true;
bool detectWordBoundary = true;
/// The [State] of the [EditableText] for which the builder will provide a
/// [EditorTextSelectionGestureDetector].
@protected
@ -354,7 +358,8 @@ class EditorTextSelectionGestureDetectorBuilder {
onDragSelectionUpdate: onDragSelectionUpdate,
onDragSelectionEnd: onDragSelectionEnd,
behavior: behavior,
child: child,
detectWordBoundary: detectWordBoundary,
child: child
);
}
}

@ -182,6 +182,7 @@ class QuillEditor extends StatefulWidget {
this.onImagePaste,
this.customShortcuts,
this.customActions,
this.detectWordBoundary = true,
Key? key})
: super(key: key);
@ -399,6 +400,8 @@ class QuillEditor extends StatefulWidget {
final Map<LogicalKeySet, Intent>? customShortcuts;
final Map<Type, Action<Intent>>? customActions;
final bool detectWordBoundary;
@override
QuillEditorState createState() => QuillEditorState();
}
@ -413,7 +416,8 @@ class QuillEditorState extends State<QuillEditor>
void initState() {
super.initState();
_selectionGestureDetectorBuilder =
_QuillEditorSelectionGestureDetectorBuilder(this);
_QuillEditorSelectionGestureDetectorBuilder(this,
widget.detectWordBoundary);
}
@override
@ -591,10 +595,11 @@ class QuillEditorState extends State<QuillEditor>
class _QuillEditorSelectionGestureDetectorBuilder
extends EditorTextSelectionGestureDetectorBuilder {
_QuillEditorSelectionGestureDetectorBuilder(this._state)
: super(delegate: _state);
_QuillEditorSelectionGestureDetectorBuilder(this._state, this._detectWordBoundary)
: super(delegate: _state, detectWordBoundary: _detectWordBoundary);
final QuillEditorState _state;
final bool _detectWordBoundary;
@override
void onForcePressStart(ForcePressDetails details) {
@ -712,9 +717,15 @@ class _QuillEditorSelectionGestureDetectorBuilder
case PointerDeviceKind.unknown:
// On macOS/iOS/iPadOS a touch tap places the cursor at the edge
// of the word.
renderEditor!
..selectWordEdge(SelectionChangedCause.tap)
..onSelectionCompleted();
if (_detectWordBoundary) {
renderEditor!
..selectWordEdge(SelectionChangedCause.tap)
..onSelectionCompleted();
} else {
renderEditor!
..selectPosition(cause: SelectionChangedCause.tap)
..onSelectionCompleted();
}
break;
case PointerDeviceKind.trackpad:
// TODO: Handle this case.

@ -714,6 +714,7 @@ class EditorTextSelectionGestureDetector extends StatefulWidget {
this.onDragSelectionUpdate,
this.onDragSelectionEnd,
this.behavior,
this.detectWordBoundary = true,
Key? key,
}) : super(key: key);
@ -789,6 +790,8 @@ class EditorTextSelectionGestureDetector extends StatefulWidget {
/// Child below this widget.
final Widget child;
final bool detectWordBoundary;
@override
State<StatefulWidget> createState() =>
_EditorTextSelectionGestureDetectorState();

Loading…
Cancel
Save