Skip to main content

Module pane_group

Module pane_group 

Source
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): apply cumulative_shift and 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 at to_len - 1.
  • Row past this hunk: accumulate the length delta into cumulative_shift and 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§

HunkRowMapper
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 HunkIndex and the input row; exposed for direct unit testing without round-tripping through RowMapper. D.4.b-shape alias for map_between(index, 0, 1, row).
map_between
D.6.b: translate a row from from_pane to to_pane where each pane is a slot index into Hunk::ranges (0/1 in two-way; 0/1/2 in three-way). Pure function of the published HunkIndex + indices; exposed for direct unit testing without round-tripping through RowMapper and 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 for map_between(index, 1, 0, row).