onDragSelectionStart method

  1. @protected
void onDragSelectionStart(
  1. TapDragStartDetails details
)

Handler for TextSelectionGestureDetector.onDragSelectionStart.

By default, it selects a text position specified in details.

See also:

Implementation

@protected
void onDragSelectionStart(TapDragStartDetails details) {
  if (!delegate.selectionEnabled) {
    return;
  }
  final PointerDeviceKind? kind = details.kind;
  _shouldShowSelectionToolbar = kind == null
    || kind == PointerDeviceKind.touch
    || kind == PointerDeviceKind.stylus;

  _dragStartSelection = renderEditable.selection;
  _dragStartScrollOffset = _scrollPosition;
  _dragStartViewportOffset = renderEditable.offset.pixels;
  _dragBeganOnPreviousSelection = _positionOnSelection(details.globalPosition, _dragStartSelection);

  if (_TextSelectionGestureDetectorState._getEffectiveConsecutiveTapCount(details.consecutiveTapCount) > 1) {
    // Do not set the selection on a consecutive tap and drag.
    return;
  }

  if (_isShiftPressed && renderEditable.selection != null && renderEditable.selection!.isValid) {
    switch (defaultTargetPlatform) {
      case TargetPlatform.iOS:
      case TargetPlatform.macOS:
        _expandSelection(details.globalPosition, SelectionChangedCause.drag);
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
      case TargetPlatform.linux:
      case TargetPlatform.windows:
        _extendSelection(details.globalPosition, SelectionChangedCause.drag);
    }
  } else {
    switch (defaultTargetPlatform) {
      case TargetPlatform.iOS:
        switch (details.kind) {
          case PointerDeviceKind.mouse:
          case PointerDeviceKind.trackpad:
            renderEditable.selectPositionAt(
              from: details.globalPosition,
              cause: SelectionChangedCause.drag,
            );
          case PointerDeviceKind.stylus:
          case PointerDeviceKind.invertedStylus:
          case PointerDeviceKind.touch:
          case PointerDeviceKind.unknown:
            // For iOS platforms, a touch drag does not initiate unless the
            // editable has focus and the drag began on the previous selection.
            assert(_dragBeganOnPreviousSelection != null);
            if (renderEditable.hasFocus && _dragBeganOnPreviousSelection!) {
              renderEditable.selectPositionAt(
                from: details.globalPosition,
                cause: SelectionChangedCause.drag,
              );
              _showMagnifierIfSupportedByPlatform(details.globalPosition);
            }
          case null:
        }
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
        switch (details.kind) {
          case PointerDeviceKind.mouse:
          case PointerDeviceKind.trackpad:
            renderEditable.selectPositionAt(
              from: details.globalPosition,
              cause: SelectionChangedCause.drag,
            );
          case PointerDeviceKind.stylus:
          case PointerDeviceKind.invertedStylus:
          case PointerDeviceKind.touch:
          case PointerDeviceKind.unknown:
            // For Android, Fucshia, and iOS platforms, a touch drag
            // does not initiate unless the editable has focus.
            if (renderEditable.hasFocus) {
              renderEditable.selectPositionAt(
                from: details.globalPosition,
                cause: SelectionChangedCause.drag,
              );
              _showMagnifierIfSupportedByPlatform(details.globalPosition);
            }
          case null:
        }
      case TargetPlatform.linux:
      case TargetPlatform.macOS:
      case TargetPlatform.windows:
        renderEditable.selectPositionAt(
          from: details.globalPosition,
          cause: SelectionChangedCause.drag,
        );
    }
  }
}