@@ -32,19 +32,6 @@ export 'package:flutter/services.dart' show TextSelectionDelegate;
32
32
/// called.
33
33
const Duration _kDragSelectionUpdateThrottle = Duration (milliseconds: 50 );
34
34
35
- /// Signature for when a pointer that's dragging to select text has moved again.
36
- ///
37
- /// The first argument [startDetails] contains the details of the event that
38
- /// initiated the dragging.
39
- ///
40
- /// The second argument [updateDetails] contains the details of the current
41
- /// pointer movement. It's the same as the one passed to [DragGestureRecognizer.onUpdate] .
42
- ///
43
- /// This signature is different from [GestureDragUpdateCallback] to make it
44
- /// easier for various text fields to use [TextSelectionGestureDetector] without
45
- /// having to store the start position.
46
- typedef DragSelectionUpdateCallback = void Function (DragStartDetails startDetails, DragUpdateDetails updateDetails, int tapCount);
47
-
48
35
/// The type for a Function that builds a toolbar's container with the given
49
36
/// child.
50
37
///
@@ -2115,7 +2102,7 @@ class TextSelectionGestureDetectorBuilder {
2115
2102
/// * [TextSelectionGestureDetector.onDragSelectionUpdate] , which triggers
2116
2103
/// this callback./lib/src/material/text_field.dart
2117
2104
@protected
2118
- void onDragSelectionUpdate (DragStartDetails startDetails, DragUpdateDetails updateDetails , int tapCount) {
2105
+ void onDragSelectionUpdate (DragUpdateDetails details , int tapCount) {
2119
2106
if (! delegate.selectionEnabled) {
2120
2107
return ;
2121
2108
}
@@ -2125,32 +2112,33 @@ class TextSelectionGestureDetectorBuilder {
2125
2112
final Offset startOffset = renderEditable.maxLines == 1
2126
2113
? Offset (renderEditable.offset.pixels - _dragStartViewportOffset, 0.0 )
2127
2114
: Offset (0.0 , renderEditable.offset.pixels - _dragStartViewportOffset);
2115
+ final Offset dragStartGlobalPosition = details.globalPosition - details.offsetFromOrigin;
2128
2116
2129
2117
// Select word by word.
2130
2118
if (tapCount == 2 ) {
2131
2119
return renderEditable.selectWordsInRange (
2132
- from: startDetails.globalPosition - startOffset,
2133
- to: updateDetails .globalPosition,
2120
+ from: dragStartGlobalPosition - startOffset,
2121
+ to: details .globalPosition,
2134
2122
cause: SelectionChangedCause .drag,
2135
2123
);
2136
2124
}
2137
2125
return renderEditable.selectPositionAt (
2138
- from: startDetails.globalPosition - startOffset,
2139
- to: updateDetails .globalPosition,
2126
+ from: dragStartGlobalPosition - startOffset,
2127
+ to: details .globalPosition,
2140
2128
cause: SelectionChangedCause .drag,
2141
2129
);
2142
2130
}
2143
2131
2144
2132
if (_shiftTapDragSelection! .isCollapsed
2145
2133
|| (defaultTargetPlatform != TargetPlatform .iOS
2146
2134
&& defaultTargetPlatform != TargetPlatform .macOS)) {
2147
- return _extendSelection (updateDetails .globalPosition, SelectionChangedCause .drag);
2135
+ return _extendSelection (details .globalPosition, SelectionChangedCause .drag);
2148
2136
}
2149
2137
2150
2138
// If the drag inverts the selection, Mac and iOS revert to the initial
2151
2139
// selection.
2152
2140
final TextSelection selection = editableText.textEditingValue.selection;
2153
- final TextPosition nextExtent = renderEditable.getPositionForPoint (updateDetails .globalPosition);
2141
+ final TextPosition nextExtent = renderEditable.getPositionForPoint (details .globalPosition);
2154
2142
final bool isShiftTapDragSelectionForward =
2155
2143
_shiftTapDragSelection! .baseOffset < _shiftTapDragSelection! .extentOffset;
2156
2144
final bool isInverted = isShiftTapDragSelectionForward
@@ -2179,7 +2167,7 @@ class TextSelectionGestureDetectorBuilder {
2179
2167
SelectionChangedCause .drag,
2180
2168
);
2181
2169
} else {
2182
- _extendSelection (updateDetails .globalPosition, SelectionChangedCause .drag);
2170
+ _extendSelection (details .globalPosition, SelectionChangedCause .drag);
2183
2171
}
2184
2172
}
2185
2173
@@ -2321,7 +2309,7 @@ class TextSelectionGestureDetector extends StatefulWidget {
2321
2309
/// The frequency of calls is throttled to avoid excessive text layout
2322
2310
/// operations in text fields. The throttling is controlled by the constant
2323
2311
/// [_kDragSelectionUpdateThrottle] .
2324
- final DragSelectionUpdateCallback ? onDragSelectionUpdate;
2312
+ final GestureTapAndDragUpdateCallback ? onDragSelectionUpdate;
2325
2313
2326
2314
/// Called when a mouse that was previously dragging is released.
2327
2315
final GestureDragEndCallback ? onDragSelectionEnd;
@@ -2376,17 +2364,13 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
2376
2364
widget.onSingleTapCancel? .call ();
2377
2365
}
2378
2366
2379
- DragStartDetails ? _lastDragStartDetails;
2380
2367
DragUpdateDetails ? _lastDragUpdateDetails;
2381
2368
Timer ? _dragUpdateThrottleTimer;
2382
2369
int ? _dragTapCount;
2383
2370
2384
2371
void _handleDragStart (DragStartDetails details, int tapCount) {
2385
2372
print ('drag start' );
2386
- assert (_lastDragStartDetails == null );
2387
- print ('passed assert' );
2388
2373
print ('tap count $tapCount ' );
2389
- _lastDragStartDetails = details;
2390
2374
if (tapCount != 2 ) {
2391
2375
widget.onDragSelectionStart? .call (details);
2392
2376
}
@@ -2408,15 +2392,13 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
2408
2392
/// Once the drag gesture ends, any pending drag update will be fired
2409
2393
/// immediately. See [_handleDragEnd] .
2410
2394
void _handleDragUpdateThrottled () {
2411
- assert (_lastDragStartDetails != null );
2412
2395
assert (_lastDragUpdateDetails != null );
2413
- widget.onDragSelectionUpdate? .call (_lastDragStartDetails ! , _lastDragUpdateDetails! , _dragTapCount! );
2396
+ widget.onDragSelectionUpdate? .call (_lastDragUpdateDetails! , _dragTapCount! );
2414
2397
_dragUpdateThrottleTimer = null ;
2415
2398
_lastDragUpdateDetails = null ;
2416
2399
}
2417
2400
2418
2401
void _handleDragEnd (TapUpDetails upDetails, DragEndDetails endDetails, int tapCount) {
2419
- assert (_lastDragStartDetails != null );
2420
2402
print ('drag end' );
2421
2403
print ('tap count $tapCount ' );
2422
2404
_handleTapUp (upDetails, tapCount);
@@ -2429,7 +2411,6 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
2429
2411
widget.onDragSelectionEnd? .call (endDetails);
2430
2412
_dragTapCount = null ;
2431
2413
_dragUpdateThrottleTimer = null ;
2432
- _lastDragStartDetails = null ;
2433
2414
_lastDragUpdateDetails = null ;
2434
2415
}
2435
2416
0 commit comments