redlineDiff function
Builds a line-based redline diff aligning unchanged lines via LCS.
Lines present in both texts (in order) are RedlineOp.unchanged; the rest
are RedlineOp.removed/RedlineOp.added. When pairChanges is true an
adjacent removed+added run is paired index-by-index into RedlineOp.changed
entries, so a one-line edit reads as a change rather than delete+insert.
Handles empty, identical, all-added and all-removed inputs.
Example:
redlineDiff(['a', 'b'], ['a', 'c']); // unchanged a, changed b->c
Audited: 2026-06-12 11:26 EDT
Implementation
List<RedlineEntry> redlineDiff(
List<String> oldLines,
List<String> newLines, {
bool pairChanges = true,
}) {
// Walk the LCS table to emit removed/added/unchanged in source order, then
// optionally collapse adjacent remove+add runs into change entries.
final List<List<int>> lcs = _lcsTable(oldLines, newLines);
final List<RedlineEntry> raw = _emitFromLcs(oldLines, newLines, lcs);
return pairChanges ? _pairAdjacent(raw) : List.unmodifiable(raw);
}