Expand description
MG.24a: magit-hunk-mode — the minor that owns diff content.
Design fragment:
docs/dev/architecture/magit-hunk-mode.md.
Five majors render unified diff, and each declared its own chords
for acting on it. The set had drifted: magit-status had s/u/x,
magit-diff had s/u and no x, and magit-commit,
magit-revision and magit-stash-show had none at all — eight
declarations covering three actions, eleven of fifteen cells empty.
Nobody noticed the missing x because there was no single place it
should have been, which is the failure mode a copied set has: a
gap in it does not announce itself.
So the chords live here, on the mode that says what the buffer’s content is, while the major keeps saying what the buffer is.
The machinery did not move. resolve_hunk, HunkOp, the
DiffSource gate and MG.18e’s region rewrite stay in
magit_core_mode where MG.18 put them; this mode contributes the
bindings and the handlers that call them. Only the bindings were in
the wrong place.
<CR> moved here once the seam existed. The chord and the
diff-path parsing belong to the mode; which version of the file to
open belongs to the view, because it genuinely differs — the index
blob for a staged diff, the live file for an unstaged one, the file
at a sha for a revision, the stash’s copy for a stash. That is
MagitView::diff_target.
Magit-status’s <CR> is context-aware over rows that are not diffs
at all (a file entry, a stash, a commit), and a minor’s binding
wins over a major’s — so that behaviour is reached through
MagitView::visit_at_cursor rather than being replaced by a
diff-only handler.
Structs§
- Magit
Hunk Guard - MG.45: deregisters this buffer’s diff-fold source.
- Magit
Hunk Mode