removeBlockAt method

List<String> removeBlockAt(
  1. int blockStartInd
)

Implementation

List<String> removeBlockAt(int blockStartInd) {
  int blockLevel = 0;

  // Find the { of the given block
  int nowLineInd = blockStartInd;
  while (blockLevel == 0 && nowLineInd != length) {
    blockLevel += r'{'.allMatches(this[nowLineInd]).length;
    nowLineInd++;
  }

  while (blockLevel != 0 && nowLineInd != length) {
    blockLevel += r'{'.allMatches(this[nowLineInd]).length;
    blockLevel -= r'}'.allMatches(this[nowLineInd]).length;
    nowLineInd++;
  }

  final removingBlock = sublist(blockStartInd, nowLineInd);
  removeRange(blockStartInd, nowLineInd);
  return removingBlock;
}