setFloatingCursor method

  1. @override
void setFloatingCursor(
  1. FloatingCursorDragState dragState,
  2. Offset boundedOffset,
  3. TextPosition textPosition, {
  4. double? resetLerpValue,
})
override

Sets the screen position of the floating cursor and the text position closest to the cursor. resetLerpValue drives the size of the floating cursor. See EditorState.floatingCursorResetController.

Implementation

@override
void setFloatingCursor(FloatingCursorDragState dragState, Offset boundedOffset, TextPosition textPosition,
    {double? resetLerpValue}) {
  if (floatingCursorDisabled) return;

  if (dragState == FloatingCursorDragState.Start) {
    _relativeOrigin = Offset.zero;
    _previousOffset = null;
    _resetOriginOnBottom = false;
    _resetOriginOnTop = false;
    _resetOriginOnRight = false;
    _resetOriginOnBottom = false;
  }
  _floatingCursorOn = dragState != FloatingCursorDragState.End;
  if (_floatingCursorOn) {
    _floatingCursorTextPosition = textPosition;
    final sizeAdjustment = resetLerpValue != null
        ? EdgeInsets.lerp(_kFloatingCaretSizeIncrease, EdgeInsets.zero, resetLerpValue)!
        : _kFloatingCaretSizeIncrease;
    final child = childAtPosition(textPosition);
    final caretPrototype = child.getCaretPrototype(child.globalToLocalPosition(textPosition));
    _floatingCursorRect = sizeAdjustment.inflateRect(caretPrototype).shift(boundedOffset);
    _cursorController.setFloatingCursorTextPosition(_floatingCursorTextPosition);
  } else {
    _floatingCursorRect = null;
    _cursorController.setFloatingCursorTextPosition(null);
  }
}