Merge pull request #1 from nguoidilam/luklak/custom_single_tap

custom single tap
pull/1326/head
notfull123 2 years ago committed by GitHub
commit 0c8e2ca418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      lib/src/widgets/editor.dart

@ -721,9 +721,23 @@ class _QuillEditorSelectionGestureDetectorBuilder
// 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.
if (_detectWordBoundary) { if (_detectWordBoundary) {
final TextSelection previousSelection = renderEditor!.selection;
final TextPosition textPosition = renderEditor!.getPositionForOffset(details.globalPosition);
final bool isAffinityTheSame = textPosition.affinity == previousSelection.affinity;
if (((_positionWasOnSelectionExclusive(textPosition) && !previousSelection.isCollapsed)
|| (_positionWasOnSelectionInclusive(textPosition) && previousSelection.isCollapsed && isAffinityTheSame))
&& renderEditor!._hasFocus) {
editor!.showToolbar();
} else {
renderEditor! renderEditor!
..selectWordEdge(SelectionChangedCause.tap) ..selectWordEdge(SelectionChangedCause.tap)
..onSelectionCompleted(); ..onSelectionCompleted();
if (previousSelection == editor!.textEditingValue.selection && renderEditor!._hasFocus) {
editor!.showToolbar();
} else {
editor!.hideToolbar(false);
}
}
} else { } else {
renderEditor! renderEditor!
..selectPosition(cause: SelectionChangedCause.tap) ..selectPosition(cause: SelectionChangedCause.tap)
@ -785,6 +799,26 @@ class _QuillEditorSelectionGestureDetectorBuilder
} }
super.onSingleLongTapEnd(details); super.onSingleLongTapEnd(details);
} }
bool _positionWasOnSelectionExclusive(TextPosition textPosition) {
final TextSelection? selection = renderEditor!.selection;
if (selection == null) {
return false;
}
return selection.start < textPosition.offset
&& selection.end > textPosition.offset;
}
bool _positionWasOnSelectionInclusive(TextPosition textPosition) {
final TextSelection? selection = renderEditor!.selection;
if (selection == null) {
return false;
}
return selection.start <= textPosition.offset
&& selection.end >= textPosition.offset;
}
} }
/// Signature for the callback that reports when the user changes the selection /// Signature for the callback that reports when the user changes the selection

Loading…
Cancel
Save