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

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

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

Loading…
Cancel
Save