DiffLayout constructor

DiffLayout(
  1. List<FileDiff> files, {
  2. DiffMode mode = DiffMode.unified,
  3. Set<int> collapsed = const {},
  4. Set<DiffGapId> expanded = const {},
  5. Map<DiffGapId, GapExpansion> expansions = const {},
  6. int contextThreshold = 0,
  7. bool expandAll = false,
  8. Set<DiffGapId> collapsedHunks = const {},
  9. bool showHunkHeaders = false,
})

Indexes logical diff rows without allocating a list of every row.

Implementation

DiffLayout(
  List<FileDiff> files, {
  this.mode = DiffMode.unified,
  Set<int> collapsed = const {},
  Set<DiffGapId> expanded = const {},
  Map<DiffGapId, GapExpansion> expansions = const {},
  int contextThreshold = 0,
  bool expandAll = false,
  Set<DiffGapId> collapsedHunks = const {},
  bool showHunkHeaders = false,
}) {
  RangeError.checkNotNegative(contextThreshold, 'contextThreshold');
  for (var f = 0; f < files.length; f++) {
    final file = files[f];
    final closed = file.path.isNotEmpty && collapsed.contains(f);
    if (file.path.isNotEmpty) _one(DiffFileHeaderRow(f, collapsed: closed));
    if (closed) continue;
    if (file.isBinary) {
      _one(DiffNoticeRow(f, DiffNotice.binary));
      continue;
    }
    if (file.hunks.isEmpty) {
      _one(DiffNoticeRow(f, _noticeFor(file)));
      continue;
    }
    for (var h = 0; h <= file.hunks.length; h++) {
      final id = (file: f, hunk: h);
      final full = expandAll || expanded.contains(id);
      final gapHidden = _gap(
        file,
        id,
        full,
        expansions[id],
        contextThreshold,
      );
      if (h == file.hunks.length) break;
      final folded = collapsedHunks.contains(id);
      if (folded ||
          showHunkHeaders ||
          gapHidden ||
          (!full && expansions[id] == null)) {
        _hunkHeaders[(f, file.hunks[h].newStart)] = _length;
        _one(DiffHunkHeaderRow(f, file.hunks[h], collapsed: folded));
      }
      if (!folded) _hunk(f, file.hunks[h]);
    }
  }
}