addFunction method

void addFunction({
  1. required AwsFormatOptionMD formatOption,
})

Implementation

void addFunction({
  required AwsFormatOptionMD formatOption,
}) {
  if (kDebugMode) {
    print('addFunction');
  }
  textApplyOption = AwsTextApplyOptionMD.noneAddNew;
  switch (formatOption) {
    case AwsFormatOptionMD.formatStartEnd:
      newText = controller.text.substring(selection.start, selection.end);
      newLine == true
          ? newText = '\n$character\n$newText\n$character'
          : newText = '$character$newText$character';
      break;
    case AwsFormatOptionMD.formatStart:
      newText = controller.text.substring(selection.start, selection.end);
      newLine == true
          ? newText = '$character$newText'
          : newText = '$character$newText';
      break;
    case AwsFormatOptionMD.formatList:
      newText = controller.text.substring(selection.start, selection.end);
      var lines = newText.split('\n');
      var orderedIndex = 0;

      for (var i = 0; i < lines.length; i++) {
        if (lines[i].isNotEmpty) {
          if (orderedList == true) {
            lines[i] = '${orderedIndex + 1}. ${lines[i]}';
            orderedIndex++;
          } else {
            lines[i] = '$character${lines[i]}';
          }
        }
      }

      newText = lines.join('\n');
      break;
    case AwsFormatOptionMD.formatAddNew:
      newLine == true
          ? newText = '\n$character$newText\n'
          : newText = '$character$newText';
      newText = character!;
      break;
    default:
      break;
  }
}