convertTextInputSelectionToTextPainterSelection function Null safety

TextSelection convertTextInputSelectionToTextPainterSelection(
  1. InlineSpan text,
  2. TextSelection selection
)

Implementation

TextSelection convertTextInputSelectionToTextPainterSelection(
    InlineSpan text, TextSelection selection) {
  if (selection.isValid) {
    if (selection.isCollapsed) {
      final TextPosition extent =
          convertTextInputPostionToTextPainterPostion(text, selection.extent);
      if (selection.extent != extent) {
        selection = selection.copyWith(
            baseOffset: extent.offset,
            extentOffset: extent.offset,
            affinity: selection.affinity,
            isDirectional: selection.isDirectional);
        return selection;
      }
    } else {
      final TextPosition extent =
          convertTextInputPostionToTextPainterPostion(text, selection.extent);

      final TextPosition base =
          convertTextInputPostionToTextPainterPostion(text, selection.base);

      if (selection.extent != extent || selection.base != base) {
        selection = selection.copyWith(
            baseOffset: base.offset,
            extentOffset: extent.offset,
            affinity: selection.affinity,
            isDirectional: selection.isDirectional);
        return selection;
      }
    }
  }

  return selection;
}