From 54520ad108e0105658fc9656faa2487efa94041a Mon Sep 17 00:00:00 2001 From: Bui Minh Anh Date: Mon, 8 May 2023 16:03:27 +0700 Subject: [PATCH 1/2] custom onSingleTapUp show toolbar --- lib/src/widgets/editor.dart | 40 ++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 906b67fb..3c997349 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -721,9 +721,23 @@ class _QuillEditorSelectionGestureDetectorBuilder // On macOS/iOS/iPadOS a touch tap places the cursor at the edge // of the word. if (_detectWordBoundary) { - renderEditor! - ..selectWordEdge(SelectionChangedCause.tap) - ..onSelectionCompleted(); + 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! + ..selectWordEdge(SelectionChangedCause.tap) + ..onSelectionCompleted(); + if (previousSelection == editor!.textEditingValue.selection && renderEditor!._hasFocus) { + editor!.showToolbar(); + } else { + editor!.hideToolbar(false); + } + } } else { renderEditor! ..selectPosition(cause: SelectionChangedCause.tap) @@ -1932,4 +1946,24 @@ class RenderEditableContainerBox extends RenderBox return defaultComputeDistanceToFirstActualBaseline(baseline)! + _resolvedPadding!.top; } + + 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; + } } From 87a33a84b21a4d188a3ef03907ee6c66427e5c6d Mon Sep 17 00:00:00 2001 From: Bui Minh Anh Date: Mon, 8 May 2023 16:27:17 +0700 Subject: [PATCH 2/2] update code custom single tap --- lib/src/widgets/editor.dart | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 3c997349..5533eaff 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -799,6 +799,26 @@ class _QuillEditorSelectionGestureDetectorBuilder } 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 @@ -1946,24 +1966,4 @@ class RenderEditableContainerBox extends RenderBox return defaultComputeDistanceToFirstActualBaseline(baseline)! + _resolvedPadding!.top; } - - 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; - } }