Expand description
D.4.b (2026-05-29) / D.6.b (2026-05-31): HunkRowMapper.
[RowMapper] impl that translates rows between two or
three sides of a diff session. Composed with the D.4.a
[PaneGroup] substrate; consumed by :diffsplit /
:diffthis in D.4.d for two-way and D.6.c for three-way.
See docs/dev/architecture/pane-groups.md and
docs/dev/architecture/diff-system.md §5.2.
§Algorithm
The walk is pane-index parametric: given a (from_pane,
to_pane) pair (positions into Hunk::ranges), for each
hunk the mapper tracks a cumulative_shift = sum over
preceding hunks of to_len - from_len.
- Row before this hunk (
row < from_r.start): applycumulative_shiftand return — the row sits in a “gap” of pure-identity territory shifted by every prior hunk’s length delta. - Row inside this hunk (
from_r.start <= row < from_r.end):- Either side empty (Add ⇒ from empty; Remove ⇒
to empty) ⇒ collapse to
to_r.start. There’s no meaningful proportional mapping when one side has zero lines to map into. - Otherwise proportional:
offset * to_len / from_len, capped atto_len - 1.
- Either side empty (Add ⇒ from empty; Remove ⇒
to empty) ⇒ collapse to
- Row past this hunk: accumulate the length delta
into
cumulative_shiftand continue. - Past all hunks: apply final
cumulative_shift.
All directions (2 in two-way, 6 in three-way) collapse
to one body via map_between; the public
map_baseline_to_current / map_current_to_baseline
are thin aliases preserved for back-compat with D.4.b
callers.
§Why the trait works with raw indices
[RowMapper::map_row] receives (from_idx, to_idx, row)
over PaneGroup::members. HunkRowMapper is
constructed with the member indices for each role
(HunkRowMapper::new for two-way; HunkRowMapper::three_pane
for three-way), and resolves each side of the
(from_idx, to_idx) pair to its pane-index slot in
Hunk::ranges (0/1 in two-way; 0/1/2 in three-way).
Any (from, to) pair that doesn’t match a known role
falls back to identity, so unfamiliar member
configurations never produce silently wrong scrolling.
Structs§
- Hunk
RowMapper - D.4.b / D.6.b: maps rows between two or three sides of a diff session.
Functions§
- map_
baseline_ to_ current - Translate a baseline-side row to its current-side
counterpart. Pure function of the published
HunkIndexand the input row; exposed for direct unit testing without round-tripping throughRowMapper. D.4.b-shape alias formap_between(index, 0, 1, row). - map_
between - D.6.b: translate a row from
from_panetoto_panewhere each pane is a slot index intoHunk::ranges(0/1 in two-way; 0/1/2 in three-way). Pure function of the publishedHunkIndex+ indices; exposed for direct unit testing without round-tripping throughRowMapperand as the body all directional aliases call into. - map_
current_ to_ baseline - Translate a current-side row to its baseline-side
counterpart. Symmetric to
map_baseline_to_current. Alias formap_between(index, 1, 0, row).