DiffLayout constructor
DiffLayout(})
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]);
}
}
}