copyCells method

bool copyCells(
  1. List<Pair<int, int>> origins,
  2. List<Pair<int, int>> destinations,
  3. String languageCode
)

It takes two lists of pairs of integers, and returns a string that represents the code that will be executed by the interpreter

Args: origins (List<Pair<int, int>>): The list of cells that will be copied. destinations (List<Pair<int, int>>): The list of cells to be copied to.

Implementation

bool copyCells(
  List<Pair<int, int>> origins,
  List<Pair<int, int>> destinations,
  String languageCode,
) {
  final List<String> destinationPosition = <String>[];
  for (final Pair<int, int> i in destinations) {
    destinationPosition.add("${rows[i.first]}${i.second + 1}");
  }
  String code = "";
  if (copyCommandsBuffer.isNotEmpty) {
    final String firstDestination =
        copyCommandsBuffer.removeAt(0).replaceAll(RegExp("[go()]"), "");
    destinationPosition.insert(0, firstDestination);
    code = "copy({${copyCommandsBuffer.joinToString(separator: ",")}},"
        "{${destinationPosition.joinToString(separator: ",")}})";
    copyCommandsBuffer.clear();
  } else {
    final List<String> originsPosition = <String>[];
    for (final Pair<int, int> i in origins) {
      originsPosition.add("${rows[i.first]}${i.second + 1}");
    }
    code = "copy({${originsPosition.joinToString(separator: ",")}},"
        "{${destinationPosition.joinToString(separator: ",")}})";
  }
  validCommandsBuffer.add(code);
  allCommandsBuffer.addAll(parseToContainer(code, languageCode));
  _interpreter.reset();
  final Pair<cat.Results, cat.CatError> res = _interpreter.validateOnScheme(
    validCommandsBuffer.joinToString(),
    SchemasReader().currentIndex,
  );
  if (res.second != cat.CatError.none) {
    allCommandsBuffer.removeLast();
    validCommandsBuffer.removeLast();
    _interpreter
      ..reset()
      ..validateOnScheme(
        validCommandsBuffer.joinToString(),
        SchemasReader().currentIndex,
      );
  }
  notifyListeners();

  return res.second != cat.CatError.none;
}