Skip to main content

Module diff_preview

Module diff_preview 

Source
Expand description

Re-number a line-level diff between two file versions into a compact current-file preview.

Removed lines are omitted from the preview; added and kept (context) lines are anchored to their post-edit positions so a follow-up edit can reuse visible concrete lines directly. Long contiguous added runs are summarized with a marker instead of echoing every inserted line, and long runs of unchanged lines are trimmed to a configurable context window around each change.

Ported from omp packages/hashline/src/diff-preview.ts, adapted to take the before/after text directly (the crate’s CompactDiffPreview type) rather than a pre-formatted <sign><lineNum>|<content> diff string.

Functions§

build_compact_diff_preview
Build a compact before/after diff preview. Added and context (unchanged) lines are numbered at their post-edit positions; unchanged lines far from any change are trimmed to CompactDiffOptions::max_unchanged_context lines on each side; long added runs are collapsed with a marker.